Jump to content
Banner by ~ Kyoshi Frost Wolf

Post what you're programming at the moment!


Ashbad

Recommended Posts

Forum Game!

 

Post what you're currently programming, including some source code and an explanation. Doesn't need to be fancy, just a little thing or two about it. Post as often as you can with your latest coding endeavors!

 

I'll start.

 

void __asm led_operations4(void) {
push_button_mask dcd 0x00800000
byte_mask dcd 0x000000FF
bit_mask dcd 0x00000003

mov r8, #0 // counter
ldr r6, =0x2009C034 // P1
ldr r7, =0x2009C054 // P2
ldr r4, push_button_mask

__loop
ldr r5, [r6]
and r5, r4
teq r5, #0
bne __loop
add r8, #1
ldr r4, byte_mask
and r8, r4
mov r9, r8
asr r9, #3
lsl r9, #2
str r9, [r7]
mov r9, r8
asr r9, #2
lsl r9, #31
mov r10, r8
ldr r4, bit_mask
and r10, r4
orr r9, r10, lsl #28
str r9, [r6]
ldr r4, push_button_mask
__loop2
ldr r5, [r6]
and r5, r4
teq r5, #0
beq __loop2
b __loop
}

Some ARM-v7 Assembly code for a class I'm helping a professor teach to 4th year CE and EE undergrad students. Coming up with a few solutions to a lab where the students have to keep track of a pushbutton input and update the 8 LEDs on the dev board they're using to show in binary the amount of times the button's been pressed.

  • Brohoof 2

b_560_95_1.png

 

What has fanfiction has Ashbad written lately?

We should totally find out by clicking this link.

(Protip, turn on "Show Mature" to see more)

Link to comment
Share on other sites

/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor 

 This example code is in the public domain.
 */

void setup() {
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);

  digitalWrite(12,LOW);
  delay(1000);
  Serial.begin(9600);

  //digitalWrite(9,HIGH);
  //digitalWrite(10,LOW);

}
byte desiredSteps=0;
boolean digread;
boolean lastdigread=false;
byte steps=0;
boolean gettingData=false;
boolean printing=false;
unsigned long laststeptime=0;
byte poi[189];
byte byteloc=0;
boolean pen=true;//false;

void loop() {

  if (Serial.available())
  {
    byte serialData=Serial.read();
    if (gettingData==false)
    {
      if (serialData=='R')
      {
        resetHead();
      }
      if (serialData=='S')
      {
        gettingData=true;
        Serial.println("G");
        Serial.flush() ;
      }
    }
    else
    {
      poi[byteloc]=serialData;
      //desiredSteps=poi[byteloc];
      //Serial.println(serialData);
      //Serial.flush() ;

      if (poi[byteloc]==255)
      {
        gettingData=false;
        printing=true;
        byteloc=255;//controlled overflow
      }
      byteloc++;

    }
  }
  while (printing==true)
  {
    //Serial.println(desiredSteps);//DEBUG
    // Serial.flush();
    int sensorValue = analogRead(A0);
    if (sensorValue>200)
      digread=true;
    if (sensorValue<100)
      digread=false;
    if (digread!=lastdigread)
    {
      steps+=1;
      laststeptime=millis();

    }
    lastdigread=digread;   
    if (poi[byteloc]==255)
    {
      gettingData=true;//false;
      byteloc=0;
      printing=false;
      //reset head position, shift page, pen up

      if (pen==true)
        switchPen();
      resetHead();
      Serial.println("G");
      Serial.flush() ;
      break;
    }
        // Serial.println("B");//DEBUG
      //Serial.flush();
    desiredSteps=poi[byteloc];
     //Serial.println(de);//DEBUG
      //  Serial.flush();  
    if (steps>=desiredSteps)
    {
      digitalWrite(9,LOW);
      digitalWrite(10,LOW);
      //analogWrite(10,50);
      /*digitalWrite(10,HIGH);
       delay(1);
       digitalWrite(10,LOW);
       */
      byteloc++;
      //pen control goes here
       //  Serial.println("N");//DEBUG
      Serial.flush();
      switchPen();

    }
    else
    {
 //DEBUG

      if (millis()-laststeptime>100)
      {
        if (millis()-laststeptime<200)
          digitalWrite(9,LOW);
        else
        {
          digitalWrite(9,HIGH);
         // Serial.println("9 should be high now");
           Serial.flush(); 
        }
        }
      else
      {
        analogWrite(9,180);

      }
      //digitalWrite(9,HIGH);

      digitalWrite(10,LOW);

    }
    delay(1);
  }
}

void resetHead()//TBR
{
  if (steps!=0)
  {
  digitalWrite(10,HIGH);
  digitalWrite(9,LOW);
  delay(2000);
  digitalWrite(10,LOW);
  delay(200);//lettin things settle down a bit
  steps=0;
  desiredSteps=0;
  }
}
void switchPen()
{
  if (pen==true)
  {
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    pen=false;
  delay(100);
    digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  }
  else
  {
    analogWrite(12,180);
    digitalWrite(11,LOW);
    pen=true;
     delay(100);
    digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  }
}

Device side of code for my supa dupa printer.

 

Edit: Meh, here is the server side:

Public Class Form1

    Dim i2 As Integer
    Dim tempBitmap As Bitmap
    Dim MyColor As Color = Color.White


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close() 'Reset duino
        SerialPort1.Encoding = System.Text.Encoding.Default
        SerialPort1.Open()

        i2 = 0
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not SerialPort1.IsOpen Then
            SerialPort1.Open()
        End If
        SerialPort1.Write("R")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not SerialPort1.IsOpen Then
            SerialPort1.Open()
        End If
        SerialPort1.Write("S")
        Timer1.Enabled = True

    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Enabled = False
        Dim Stringbyte(0 To 1) As Byte
        Stringbyte(0) = CByte(TrackBar1.Value)
        SerialPort1.Write(Stringbyte, 0, 1)
        ' SerialPort1.Write(Stringbyte)
        'Label1.Text = Stringbyte(0)
        'MsgBox(Stringbyte)



    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        Dim incomingData = SerialPort1.ReadLine()
        'MsgBox(incomingData)
        If incomingData.Contains("G") Then

            i2 += 1
            For i = 0 To PictureBox1.Width - 1
                Dim tempColor As Color = tempBitmap.GetPixel(i, i2)
                If MyColor <> tempColor Then
                    MyColor = tempColor
                    'send data; delay
                    Dim Tempbyte(0 To 1) As Byte
                    Tempbyte(0) = i
                    ' If i <> 0 Then 'TBR!
                    SerialPort1.Write(Tempbyte, 0, 1)
                    'End If

                    System.Threading.Thread.Sleep(50)
                End If
            Next
            'send 255 char
            If Not SerialPort1.IsOpen Then
                SerialPort1.Open()
            End If
            Dim Stringbyte(0 To 1) As Byte
            Stringbyte(0) = 255
            SerialPort1.Write(Stringbyte, 0, 1)

            ' MsgBox(255)
            ' SerialPort1.Write(Stringbyte)

            'SerialPort1.Write("S")
        End If
        'MsgBox(SerialPort1.ReadLine())
        ' Label2.Text = SerialPort1.ReadLine()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If SerialPort1.ReadBufferSize > 0 Then
            MsgBox(SerialPort1.ReadLine())
        End If

    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Label1.Text = TrackBar1.Value
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Not SerialPort1.IsOpen Then
            SerialPort1.Open()
        End If
        SerialPort1.Write("S")
        i2 = -1 'so that it starts with 0 then
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        OpenFileDialog1.ShowDialog()

        If Dir(OpenFileDialog1.FileName) <> "" Then
            PictureBox1.ImageLocation = OpenFileDialog1.FileName
            PictureBox1.Load()
            Button4.Enabled = True
            tempBitmap = New Bitmap(PictureBox1.Image)
            'MyColor = tempBitmap.GetPixel(0, 0)
        Else
            Button4.Enabled = False
        End If
    End Sub
End Class

Edited by thegoodhen
Link to comment
Share on other sites

I recognize the latter as Visual Basic; is the former Arduino? :)

 

Anyways, revised 16 bit RGB format sprite-copying routine with a given mask color and alpha-blending transparency value:

 

void CopySpriteMaskedAlpha(const void*datar, int x, int y, int width, int height, int maskcolor, int alpha) { 
   color_t*data = (color_t*) datar; 
   color_t* VRAM = (color_t*)0xA8000000; 
   VRAM += LCD_WIDTH_PX*y + x; 
   alpha %= 32; 
   for(int j=y; j<y+height; j++) { 
      for(int i=x; i<x+width;  i++) { 
         if (*(data) != maskcolor) { 
         *(VRAM) = (color_t)((((int)(*data & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) | 
                (color_t)((((int)(*data & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0); 
           VRAM++; data++; 
         } else { VRAM++; data++; } 
      } 
      VRAM += LCD_WIDTH_PX-width; 
   } 
}
  • Brohoof 1

b_560_95_1.png

 

What has fanfiction has Ashbad written lately?

We should totally find out by clicking this link.

(Protip, turn on "Show Mature" to see more)

Link to comment
Share on other sites

I recognize the latter as Visual Basic; is the former Arduino? :)

 

Anyways, revised 16 bit RGB format sprite-copying routine with a given mask color and alpha-blending transparency value:

 

void CopySpriteMaskedAlpha(const void*datar, int x, int y, int width, int height, int maskcolor, int alpha) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
alpha %= 32;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM) = (color_t)((((int)(*data & 0xf81f) * alpha + (int)(*VRAM & 0xf81f) * (32-alpha) + 0x8010) >> 5) & 0xf81f) |
(color_t)((((int)(*data & 0x07e0) * alpha + (int)(*VRAM & 0x07e0) * (32-alpha) + 0x0400) >> 6) & 0x07e0);
VRAM++; data++;
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}

YES! Arduino and VB! :wub:

 

Anyways, that code... Ah, using all those fancy things I don't really understand xD ">>" ? single "&" ? O_o

 

You know Arduino! YOU, SIR, ARE AWSUM! B)

Link to comment
Share on other sites

<!DOCTYPE html>

<html>

<body>

 

<p>Click the button for free bacon ~~~~</p>

 

<button onclick="myFunction()">Free Bacon!</button>

<p id="demo"></p>

 

<script type="text/javascript">

function myFunction()

{

var x;

var r=confirm("Bacon YAY!");

if (r==true)

{

x="Bacon for you ~~~~!";

}

else

{

x="NO BACON FOR YOU!";

}

document.getElementById("demo").innerHTML=x;

}

</script>

 

</body>

</html>

Just messing around with stuff and buttons and such :)

Edited by DJ Scratch
  • Brohoof 1

 

 

Link to comment
Share on other sites

Anyways, that code... Ah, using all those fancy things I don't really understand xD ">>" ? single "&" ? O_o

 

>> is bitshift right, which shifts the left operator right by the amount of bits specified on the right side value. It's essentially a "divide by a power of two" operator.

 

& is bitwise AND; basically, 0b1001 AND 0b1010 would yield 0b1000 since the only bits they share in common is the most significant one.

 

<3 bitwise ops


b_560_95_1.png

 

What has fanfiction has Ashbad written lately?

We should totally find out by clicking this link.

(Protip, turn on "Show Mature" to see more)

Link to comment
Share on other sites

>> is bitshift right, which shifts the left operator right by the amount of bits specified on the right side value. It's essentially a "divide by a power of two" operator.

 

& is bitwise AND; basically, 0b1001 AND 0b1010 would yield 0b1000 since the only bits they share in common is the most significant one.

 

<3 bitwise ops

 

Oh! That is cool. Didn't know bout it. Seems to be pretty handy. But... I still don't get bitand. Isn't 1001 and 1010 supposed to be 19... I mean 10011? :/

Edit: Ohwait. I'm getting stupid when I'm tired xD I understand. Normal "and," just for bits. Duh.

Edited by thegoodhen
Link to comment
Share on other sites

Oh! That is cool. Didn't know bout it. Seems to be pretty handy. But... I still don't get bitand. Isn't 1001 and 1010 supposed to be 19... I mean 10011? :/

 

That would be 0b1001 + 0b1010 ;) As you probably already know it, here's the truth table for AND:

 

Posted Image

 

p and q would be the input boolean values, p ^ q is p AND q (the boolean algebra and general programming symbols for and are different -- ^ would be XOR in C, not AND)

 

Basically, you apply that rule to all of the bits. So, the top bit of 0b1001 is 1 and the top bit of 0b1010 is 1, so 1 AND 1 is 1. Neither bits are set in 0b1001 nor 0b1010, so that second bit would be 0 in the output. The other two bits in the two input values are only 1 in one of the input values, and 1 AND 0 is 0. So, output is 0b1000 :)

 

Bit shifts work differently. For example in the top post my assembly had the following:

 

asr r9, #3
lsl r9, #2

In C, this would be

 

value = value >> 3;
value = value << 2;

C compiles into Assembly (before into actual machine code), so the C and assembly outputs are similar, and do the same thing: shifts a value right arithmetically 3 bits, and then shifts it logically left two bits. An arithmetic shift right is in practice a signed divide by two, and doing that 3 times (since it's shifting it 3 bits) would be dividing by 2^3, or 8. It keeps the top bit intact since it acts as the +/- of a signed value. The Logical left shift shifts all bits left 2 bits in this case, and fills those bottom two bits with zeros. It's more of a crude method that isn't used for mathematical purposes, but rather more of a "I need to move these bits over this much, ignore the top bit". Hence, the difference between logical and arithmetic shifts.


b_560_95_1.png

 

What has fanfiction has Ashbad written lately?

We should totally find out by clicking this link.

(Protip, turn on "Show Mature" to see more)

Link to comment
Share on other sites

Lol.

 

 

class "BasePoke" {
hp=100,orig=100,name="Base",user=true,enemy=false,level=1,attack1='punch',attack2='punch',attack3='punch',attack4='punch',pic='vagikarp.png',bpic='vagikarpb.png',y=0,n=0,points=0,lvlpoints=100,savename=''
}
BasePoke.species = {} -- new field to keep track of all species created
function BasePoke:__init(hp,orig,name,user,enemy,level,attack1,attack2,attack3,attack4,pic,bpic,y,n)--Sets how you would name a custom pokemon
self.hp=hp
self.name=name
self.user=user
self.enemy=enemy
self.level=level
self.attack1=attack1
self.attack2=attack2
self.attack3=attack3
self.attack4=attack4
self.pic=pic
self.orig=orig
self.bpic=bpic
self.y=y
self.n=n
self.savename=''
self.savelevel=''
self.savepic=''
self.savebpic=''
self.saveattack1=''
self.saveattack2=''
self.saveattack3=''
self.saveattack4=''
table.insert(BasePoke.species,self)
end
function BasePoke:draw()--Pokemon draw
local e=love.filesystem.exists(self.pic)
local a=love.filesystem.exists(self.bpic)
if gamestate=='pokeselect' then
  love.graphics.print('level:'..self.level,font:getWidth(self.name)+6,self.y)--prints level
  if self.user==true then
   love.graphics.print('*',font:getWidth(self.name)+font:getWidth('level:'..self.level)+5,self.y)--indicates user-ness by drawing *
  end
  if self.enemy==true then
   love.graphics.print('+',font:getWidth(self.name)+font:getWidth('level:'..self.level)+5,self.y)--indicates enemy-ness by drawing +
  end
  if self.n==pokeselect then
   love.graphics.print('['..self.name..']',0,self.y)--show which pokemon you are selecting
  else
   love.graphics.print(self.name,0,self.y)--if not selected....
  end
end
if gamestate=='fight' then
  if self.user==true then
   love.graphics.print(self.name,85,122)--draw's user name
   if a then--checks if picture exists
    love.graphics.draw(love.graphics.newImage(self.bpic),0,120)--it does!
   else
    love.graphics.draw(love.graphics.newImage('graphics/vagikarpb.png'),0,120)--it doesn't 
   end
   love.graphics.rectangle('fill',85,136,self.hp*.5,4)--health bar
   love.graphics.print('lvl:'..self.level,90+(font:getWidth(self.name)),122)--level level level
  end
  if self.enemy==true then--like user, but enemy.
   love.graphics.print(self.name,85,2)
   if e then
    love.graphics.draw(love.graphics.newImage(self.pic),100,22)
   else
    love.graphics.draw(love.graphics.newImage('graphics/vagikarp.png'),100,22)
   end
   love.graphics.rectangle('fill',85,16,self.hp*.5,4)
   love.graphics.print('lvl:'..self.level,90+(font:getWidth(self.name)),2)
  end
end
if gamestate=='customize' then
  if self.user==true then
   love.graphics.print(self.name,0,0)
  end
end
end
function BasePoke:clear()
userselected=false
enemyselected=false
self.user=false
self.enemy=false
self.hp=self.orig
end
function BasePoke:update()
local readshit=love.filesystem.exists('blank.txt')--checks.
local blank=''
  if runtry==true then--Makes it so if you run, you can select again.
  self:clear()
end
if gamestate=='pokeselect' then
  if customize==true then
   if self.n==pokeselect then
    self.name=name
   end
  end
  if self.n==pokeselect then--selection!
   if userselect==true and self.enemy==false then
    self.user=true
    userselect=false
   end
   if enemyselect==true and self.user==false then
    self.enemy=true
    enemyselect=false
   end
  end
end
if user.item=='rare candy' then
  if self.user==true then
   self.level=self.level+1
  end
end
if gamestate=='fight' then
  if fight==true then--This fight system is a lil messy.  Lemme explain.
   if self.user==true then
   user.attackname[1]=self.attack1--This means that the player's attack=pokemon's attack
   user.attackname[2]=self.attack2
   user.attackname[3]=self.attack3
   user.attackname[4]=self.attack4
    if self.level<=6 and self.level>2 then--this is so attack power increases with level.
	 user.attack[n]=user.attack[n]*self.level/3
    else
	 if self.level>6 then--if level gets too big, then it becomes a standard attack rate
	  user.attack[n]=user.attack[n]*2
	 else
	  user.attack[n]=user.attack[n]--if level=1 or 2.
	 end
    end
    if enemy.attacking==true then
	 self.hp=self.hp-enemy.attack[n]--Where the damage is inflicted.  The rest is in battle.lua
    end
   end
   if self.enemy==true then
    enemy.attackname[1]=self.attack1--sets attacks
    enemy.attackname[2]=self.attack2
    enemy.attackname[3]=self.attack3
    enemy.attackname[4]=self.attack4
    if self.level<=6 and self.level>2 then--oohhh multiplying attacks
	 enemy.attack[n]=enemy.attack[n]*self.level/3
    else
	 if self.level>6 then
	  enemy.attack[n]=enemy.attack[n]*2
	 else
	  enemy.attack[n]=enemy.attack[n]
	 end
    end
    if user.attacking==true then--duh.
	 self.hp=self.hp-user.attack[q]
    end
   end
  end
end
self:levelup()
if self.hp<=0 then
  self:faint()
end
end
function BasePoke:levelup()--LEVELUP'
if self.level==8 then
   self:clear()
   self.level=1
   gamestate='pokeselect'
  end
if self.user==true and user.win==true and enemy.lose==true or self.enemy==true and enemy.win==true and user.lose==true then--really big shit right here, checks to see if someone won the fight.
  user.encounter=false
  if self.level<=6 and self.level>2 then--increasing health!
   self.hp=self.orig*self.level/3
  else
   if self.level>6 then
    self.hp=self.orig*2
   else
    self.hp=self.orig--awww level isn't high enough 
   end
  end
  self.level=self.level+1
  fight=false
end
end
function BasePoke:faint()--Self explanatory.
if self.level<=6 and self.level>2 then
   self.hp=self.orig*self.level/3
  else
   if self.level>6 then
    self.hp=self.orig*2
   else
    self.hp=self.orig
   end
  end--yes, i did copy/paste this.
if self.user==true then
  user.lose=true
end
if self.user==false then
  user.win=true
end
end

 

I haven't worked on this in like, months, but I've been meaning to start it again.


I HAD TO FALL TO LOSE IT ALL BUT IN THE END IT DOESN'T EVEN MATTER /WRISTS

On 4/28/2013 at 8:13 PM, gooM said:
Djenty...man you are crazy, but an awesome sort of crazy
Link to comment
Share on other sites

Here's just a little bit from this Java shooting gallery style game I was working on:

package com.fl.shooter;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.*;
/**
*
* @author fl
*/
public class Shooter implements Runnable {
    private Thread thread = new Thread(this);
    private GameFrame frame = new GameFrame(this);
    private boolean running = true;
    private GameLogic logic = new GameLogic();
    private Point mousePosition = new Point(0, 0);
    private boolean debug = false;
    public Shooter() {
	    frame.addMouseListener(new MouseAdapter() {
		    @Override
		    public void mousePressed(MouseEvent me) {
			    logic.fireGunAt(me.getPoint());
		    }
	    });
	    frame.addMouseMotionListener(new MouseMotionAdapter() {
		    @Override
		    public void mouseMoved(MouseEvent me) {
			    mousePosition = me.getPoint();
		    }
	    });
	    frame.addKeyListener(new KeyAdapter() {
		    @Override
		    public void keyReleased(KeyEvent ke) {
			    if (ke.getKeyCode() == KeyEvent.VK_D) {
				    debug = !debug;
			    }
		    }
	    });
    }
    public void update(long elapsedTime) {
	    logic.update(elapsedTime);
    }
    private Image gunImage = Resources.getImage("gun.png");
    private Image reticleImage = Resources.getImage("reticle.png");
    private Image flashImage = Resources.getImage("flash.png");
    public void paint(Graphics2D g) {
	    // Clear background.
	    g.setBackground(Color.black);
	    g.clearRect(0, 0, frame.getWidth(), frame.getHeight());
	    // Draw each enemy.
	    synchronized (logic.getEnemies()) {
		    for (Enemy enemy : logic.getEnemies()) {
			    g.drawImage(enemy.getSprite().getImage(), enemy.getSprite().getPoint().x, enemy.getSprite().getPoint().y, frame);
		    }
	    }
	    if (logic.drawFlash()) {
		    g.drawImage(flashImage, 0, 0, frame);
	    }
	    paintStats(g);
	    // Draw reticle.
	    g.drawImage(reticleImage, mousePosition.x - reticleImage.getWidth(frame) / 2,
			    mousePosition.y - reticleImage.getHeight(frame) / 2, frame);
	    // Draw gun.
	    g.drawImage(gunImage, mousePosition.x + 15, frame.getHeight() - gunImage.getHeight(frame), frame);
	    // Draw debug data to the screen.
	    if (debug) {
		    paintDebugData(g);
	    }
    }
    private Font statsFont = new Font("Arial Black", Font.PLAIN, 18);
    private void paintStats(Graphics2D g) {
	    int offset = 75;
	    g.setColor(Color.white);
	    g.setFont(statsFont);
	    g.drawString("shots hit: " + logic.getShotsHit(), 50, offset);
	    offset += 25;
	    g.drawString("shots total: " + logic.getShotsTotal(), 50, offset);
	    offset += 25;
	    g.drawString("% accuracy: " + logic.getAccuracy(), 50, offset);
	    offset += 25;
	    g.setColor(Color.cyan);
	    g.drawString("collaterals: " + logic.getCollaterals(), 50, offset);
    }
    private Image debug_reticleImage = Resources.getImage("reticle_debug.png");
    private Font debug_Font = new Font("Arial", Font.PLAIN, 12);
    private void paintDebugData(Graphics2D g) {
	    g.setColor(Color.yellow);
	    g.setFont(debug_Font);
	    int offset = 50;
	    g.drawString("time until next enemy: " + logic.debug_getTimeToNextEnemy(), 50, offset);
	    offset += 20;
	    synchronized (logic.getEnemies()) {
		    for (Enemy enemy : logic.getEnemies()) {
			    g.drawString("enemy " + (enemy.isDead() ? "[dead] " : "") + "lifespan: " + enemy.debug_getLifespan(), 50, offset);
			    offset += 25;
			    // Figure out how to draw bounding boxes later.
			    //g.drawRect(enemy.getX(), enemy.getY(), enemy.getType().aliveImage().getWidth(frame), enemy.getType().aliveImage().getHeight(frame));
		    }
	    }
	    for (Point point : logic.getPreviousShots()) {
		    g.drawImage(debug_reticleImage, point.x - reticleImage.getWidth(frame) / 2,
				    point.y - reticleImage.getHeight(frame) / 2, frame);
	    }
    }
    @Override
    public void run() {
	    frame.setVisible(true);
	    frame.setCursor(frame.getToolkit().createCustomCursor(
			    frame.getToolkit().getImage(""), new Point(0, 0), null));
	    long currentTime = System.currentTimeMillis();
	    while (running) {
		    long elapsedTime = System.currentTimeMillis() - currentTime;
		    currentTime += elapsedTime;
		    update(elapsedTime);
		    frame.repaint();
	    }
    }
    public void start() {
	    thread.start();
    }
    public void stop() {
	    running = false;
	    try {
		    thread.join();
	    } catch (InterruptedException ex) {
	    }
	    frame.setVisible(false);
    }
    /**
	 * @param args the command line arguments
	 */
    public static void main(String[] args) {
	    new Shooter().start();
    }
}

Still a huge WIP, also I need to brush up on Visual Basic (ugh) as it's what I'll be using in college in September.


top lel

Link to comment
Share on other sites

That would be 0b1001 + 0b1010 ;) As you probably already know it, here's the truth table for AND:

 

Posted Image

 

p and q would be the input boolean values, p ^ q is p AND q (the boolean algebra and general programming symbols for and are different -- ^ would be XOR in C, not AND)

 

Basically, you apply that rule to all of the bits. So, the top bit of 0b1001 is 1 and the top bit of 0b1010 is 1, so 1 AND 1 is 1. Neither bits are set in 0b1001 nor 0b1010, so that second bit would be 0 in the output. The other two bits in the two input values are only 1 in one of the input values, and 1 AND 0 is 0. So, output is 0b1000 :)

 

Bit shifts work differently. For example in the top post my assembly had the following:

 

asr r9, #3
lsl r9, #2

In C, this would be

 

value = value >> 3;
value = value << 2;

C compiles into Assembly (before into actual machine code), so the C and assembly outputs are similar, and do the same thing: shifts a value right arithmetically 3 bits, and then shifts it logically left two bits. An arithmetic shift right is in practice a signed divide by two, and doing that 3 times (since it's shifting it 3 bits) would be dividing by 2^3, or 8. It keeps the top bit intact since it acts as the +/- of a signed value. The Logical left shift shifts all bits left 2 bits in this case, and fills those bottom two bits with zeros. It's more of a crude method that isn't used for mathematical purposes, but rather more of a "I need to move these bits over this much, ignore the top bit". Hence, the difference between logical and arithmetic shifts.

 

I already figured that out. I was just being stupid from being tired.

Anyways.

I vaguely recall having done something like that when I was using shift registers.

Do you know Arduino? O_o Cuz that would make you 20% cooler!

 

Edit: I forgot to mention how awesome this community is. Some ponies even listen to the same music I do although now it's far from being mainstream and some know Arduino and... AWSUM!

Edited by thegoodhen
Link to comment
Share on other sites

  • 5 weeks later...

@, I'd definitely suggest you switch over to a framework more intended for game dev' than Java's built-in graphics libs. Specifically, SDL, SFML, or if you're up for it, LWJGL :)

 

 

@@thegoodhen, I don't specifically know Arduino, but I've seen it before a lot; most of what I do is in C or Assembly, I'm more a fan of close-to-hardware programming.

 

Been working on compiling some of my routines for native C/Assembly development on the Casio fxCG-10/20 Prizm, along (with the permission of the authors) with some routines of some buddies of mine who also made some nifty routines.

 

<snipped out old code>

 

 

Woo, found a backup of some missing components to my old z80-based Operating System Kernel!

 

Some goodies:

 

Some generic syscalls:

; NucleoOS string syscalls

; copy string to new location
; input: hl - source, de - destination
; comments: will copy until the first occurance of null termination

STRCPY:
    xor a
@
    cp (hl)
    ret z
    ldi
    jr {-1@}
    ret

; convert from reg8 to string
; input: a - reg8, b - 1 if signed, 0 if unsigned
; output: string in KERNEL_ITOA_LAST

ITOA_8:
    ld iyl, 0
    ld hl, KERNEL_ITOA_LAST
    push hl
    push af
    xor a
    cp b
    jr z, {@}
    pop af
    ld d, 127
    cp d
    jr c, {2@}
    ld d, '-'
    pop hl
    ld (hl), d
    inc hl
    push hl
    neg
    jr {2@}
@    
    pop af
@
    ld l, a
    ld h, 0
    ld d, 100
    push af
    call DIV_HLbyD
    ld a, l
    add a, a
    add a, a
    add a, a
    ld h, a
    add a, a
    add a, h
    add a, l
    add a, a
    add a, a
    ld d, a
    pop af
    sub d
    ld d, a
    ld a, iyl
    ld b, a
    ld a, l
    cp 0
    jr nz, {@}
    ld c, a
    xor a
    cp b
    jr z, {2@}
@
    pop hl
    add a, '0'
    ld (hl), a
    inc hl
    push hl
    inc iyl
@
    ld a, d
    ld l, a
    ld h, 0
    ld d, 10
    push af
    call DIV_HLbyD
    ld a, l
    add a, a
    add a, a
    add a, l
    add a, a
    ld d, a
    pop af
    sub d
    ld d, a
    ld a, iyl
    ld b, a
    ld a, l
    cp 0
    jr nz, {@}
    ld c, a
    xor a
    cp b
    jr z, {2@}
@
    pop hl
    add a, '0'
    ld (hl), a
    inc hl
    push hl
@
    ld a, d
    add a, '0'
    pop hl
    ld (hl), a
    xor a
    inc hl
    ld (hl), a
    ld hl, KERNEL_ITOA_LAST
    ret

; convert from reg16 to string
; input: hl - reg16, b - 1 if signed, 0 if unsigned
; output: string in KERNEL_ITOA_LAST

ITOA_16:
    ld iyl, 0
    push hl
    pop ix
    ld hl, KERNEL_ITOA_LAST
    push hl
    xor a
    cp b
    jr z, {@}
    ld a, ixh
    ld d, 127
    cp d
    jr c, {@}
    jr z, {@}
    push ix
    pop de
    ld hl, 0
    scf
    ccf
    sbc hl, de
    push hl
    pop ix
    pop hl
    ld a, '-'
    ld (hl), a
    inc hl
    push hl
@
    push ix
    pop hl
    ld de, 10000
    ld a, -1
@
    inc a
    scf
    ccf
    sbc hl, de
    jp nc, {-1@}
    add hl, de
    push hl
    pop ix
    cp 0
    jr nz, {@}
    ld a, iyl
    ld b, a
    xor a
    cp b
    jr z, {2@}
@
    add a, '0'
    pop hl
    ld (hl), a
    inc hl
    push hl
    inc iyl
@
    push ix
    pop hl
    ld de, 1000
    ld a, -1
@
    inc a
    scf
    ccf
    sbc hl, de
    jp nc, {-1@}
    add hl, de
    push hl
    pop ix
    cp 0
    jr nz, {@}
    ld a, iyl
    ld b, a
    xor a
    cp b
    jr z, {2@}
@
    add a, '0'
    pop hl
    ld (hl), a
    inc hl
    push hl
    inc iyl
@
    push ix
    pop hl
    ld de, 100
    ld a, -1
@
    inc a
    scf
    ccf
    sbc hl, de
    jp nc, {-1@}
    add hl, de
    push hl
    pop ix
    cp 0
    jr nz, {@}
    ld a, iyl
    ld b, a
    xor a
    cp b
    jr z, {2@}
@
    add a, '0'
    pop hl
    ld (hl), a
    inc hl
    push hl
    inc iyl
@
    push ix
    pop hl
    ld de, 10
    ld a, -1
@
    inc a
    scf
    ccf
    sbc hl, de
    jp nc, {-1@}
    add hl, de
    push hl
    pop ix
    cp 0
    jr nz, {@}
    ld a, iyl
    ld b, a
    xor a
    cp b
    jr z, {2@}
@
    add a, '0'
    pop hl
    ld (hl), a
    inc hl
    push hl
    inc iyl
@
    pop hl
    ld a, ixl
    cp 0
    add a, '0'
    ld (hl), a
    inc hl
    xor a
    ld (hl), a
    ld hl, KERNEL_ITOA_LAST
    ret



ITOX_8:
    push af
    ld a, '0'
    ld (KERNEL_ITOA_LAST), a
    ld a, 'x'
    ld (KERNEL_ITOA_LAST+1), a
    pop af
    push af
    srl a
    srl a
    srl a
    srl a
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+2), a
    pop af
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+3), a
    xor a
    ld (KERNEL_ITOA_LAST+4), a
    ld hl, KERNEL_ITOA_LAST
    ret

ITOX_16:
    push af
    push hl
    pop ix
    ld a, '0'
    ld (KERNEL_ITOA_LAST), a
    ld a, 'x'
    ld (KERNEL_ITOA_LAST+1), a
    ld a, ixh
    push af
    srl a
    srl a
    srl a
    srl a
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+2), a
    pop af
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+3), a
    ld a, ixl
    push af
    srl a
    srl a
    srl a
    srl a
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+4), a
    pop af
    and $0F
    ld d, 0
    ld e, a
    ld hl, ITOX_LUT
    add hl, de
    ld a, (hl)
    ld (KERNEL_ITOA_LAST+5), a
    xor a
    ld (KERNEL_ITOA_LAST+6), a
    ld hl, KERNEL_ITOA_LAST
    ret


ITOX_LUT:
.db "0123456789ABCDEF"


ITOB_8:
    ld b, 8
    ld hl, KERNEL_ITOA_LAST
    push af
    ld a, '%'
    ld (hl), a
    inc hl
    pop af
@
    rlca
    ld c, 0
    jr nc, {@}
    inc c
@
    push af
    ld a, c
    add a,'0'
    ld (hl), a
    pop af
    inc hl
    djnz {-2@}
    xor a
    ld (hl), a
    ld hl, KERNEL_ITOA_LAST
    ret

ITOB_16:
    push hl
    ld a, h
    call ITOB_8
    pop hl
    ld a, l
    ld b, 8
    ld hl, KERNEL_ITOA_LAST+9
@
    rlca
    ld c, 0
    jr nc, {@}
    inc c
@
    push af
    ld a, c
    add a,'0'
    ld (hl), a
    pop af
    inc hl
    djnz {-2@}
    xor a
    ld (hl), a
    ld hl, KERNEL_ITOA_LAST
    ret
    ret



; NucleoOS math syscalls

; multiply reg8 * reg8 -> reg16
; input: h - reg8, e - reg8
; output: hl - reg16

MUL_HxE:
MUL_ExH:
    ld d,0
    ld l,d
    ld b,8
@
    add hl,hl
    jp nc, {@}
    ld a, d
    ld e, a
    xor a
    ld d, a
    add hl, de
    ld a, e
    ld d, a
@
    djnz {-2@}
    ret

; multiply reg16 * reg16 -> [reg16:reg16]  
; input: bc - reg16, de - reg16
; output: dehl - [reg16:reg16]

MUL_BCxDE:
MUL_DExBC:
    ld hl,0
    ld a,16
@
    add hl,hl
    rl e
    rl d
    jp nc, {@}
    add hl,bc
    jp nc, {@}
    inc de
@
    dec a
    jp nz, {-2@}
    ret

; multiply reg16 / reg8 -> reg16
; input: hl - reg16, d - reg8
; output: hl - reg16

DIV_HLbyD:
    xor a
    ld b, 16
@
    add hl,hl
    rla
    cp d
    jp c, {@}
    sub d
    inc l
@
    djnz {-2@}
    ret



; NucleoOS graphical syscalls

; Draw a large sprite
; Credit goes to Venus shell, specifically Tijl Coosemans
; Input:  
;    ix=sprite address
;    a='x'
;    l='y'
;    b='height' (in pixels)
;    c='width' (in bytes, e.g. 2 would be 16)


SPRITE_PUT_LARGE:
    ld    h,0
    ld    d,h
    ld    e,l
    add    hl,de
    add    hl,de
    add    hl,hl
    add    hl,hl
    ld    e,a
    srl    e
    srl    e
    srl    e
    add    hl,de
    ld    de, KERNEL_LCD_BUF
    add    hl,de
    and    7
    ld    e,a
@
    push    bc
    push    hl
    ld    b,c
@
    ld    c,(ix)
    ld    d,0
    inc    ix
    ld    a,e
    or    a
    jr    z, {2@}
@
    srl    c
    rr    d
    dec    a
    jr    nz,{-1@}
@
    ld    a,c
    or    (hl)
    ld    (hl),a
    inc    hl
    ld    a,d
    or    (hl)
    ld    (hl),a
    djnz    {-3@}
    pop    hl
    ld    c,12
    add    hl,bc
    pop    bc
    djnz    {-4@}
    ret
SPRITE_PUT_LARGE_END:



; Draw a sprite masked to the LCD
; Credit: KermM, who derives credit from Ion's routine
; Inputs: 
;     ix = b-byte mask 
;     ix+b = b-byte sprite 
;     a,l = x and y as with IonPutSprite 
;     b= height of sprite 

SPRITE_PUT_MASK
    ld    e,l
    ld    h,$00
    ld    d,h
    add    hl,de
    add    hl,de
    add    hl,hl
    add    hl,hl
    ld    e,a
    and    $07
    ld    c,a
    srl    e
    srl    e
    srl    e
    add    hl,de
    ld    de, KERNEL_LCD_BUF
    add    hl,de
@
    ld    d,(ix)
    ld    e,$FF
    ld    a,c
    or    a
    jr    z,{2@}
@
    srl    d
    rr    e
    set 7,d
    dec    a
    jr    nz,{-1@}
@
    ld    a,(hl)
    and    d
    ld    (hl),a
    inc    hl
    ld    a,(hl)
    and    e
    ld    (hl),a
    push ix
    dec hl
    ld de,8
    add ix,de
@
    ld    d,(ix)
    ld    e,$00
    ld    a,c
    or    a
    jr    z,{2@}
@
    srl    d
    rr    e
    dec    a
    jr    nz,{-1@}
@
    ld    a,(hl)
    xor    d
    ld    (hl),a
    inc    hl
    ld    a,(hl)
    xor    e
    ld    (hl),a

    pop ix
    ld    de,$0B
    add    hl,de
    inc    ix
    djnz {-6@}
    ret
SPRITE_PUT_MASK_END:


LCD_BUF_CLEAR:
    xor a
    ld hl, KERNEL_LCD_BUF
    ld (hl), a
    inc hl
    push hl
    pop de
    dec hl
    ld bc, 767
    ldir    
    ret
LCD_BUF_CLEAR_END:


; NucleoOS util syscalls

; Get battery level
; Outputs:   a - 1 if normal, 0 if low 
GET_BATTERY_LEVEL:
    in a, ($02)
    rrca
    sub a
    ret c
    inc a
    ret
GET_BATTERY_LEVEL_END:

; Hard wait
; input: ixh - time to wait (11 is ~one second)
HARD_WAIT:
    call CPU_GET_SPEED
    cp 0
    jr z, {@}
    ld a, ixh
    add a, a
    add a, a
    add a, ixh
    sra a
    ld ixh, a
@
    ld hl, $FFFF
@
    ld de, 1
    scf
    ccf
    sbc hl, de
    ld a, ixh
    ld b, a
@    
    djnz {-1@}
    jp po, {-2@}
    ret
HARD_WAIT_SEC_END:


; NucleoOS kernel error syscalls

; print current stack address, I flag value, page, address, etc.

STACKTRACE:
    call CON_NL_S
    ld hl, str_stacktrace_1
    call PUTS
    call CON_NL_S
    ld hl, str_stacktrace_2
    call PUTS
    pop hl
    push hl
    call ITOX_16
    ld hl, KERNEL_ITOA_LAST
    call PUTS
    ld hl, str_stacktrace_3
    call PUTS
    ld hl, 0
    add hl, sp
    call ITOX_16
    call PUTS
    ld c, ' '
    call PUTC
        call CONU
        call LCD_UPDATE
        call LCD_BUF_CLEAR
    ret



str_stacktrace_1:
.db "Kernel Stacktrace:", 0
str_stacktrace_2:
.db "PC: ",0
str_stacktrace_3:
.db " SP: ",0
str_stacktrace_4:
.db "I: ",0



; NucleoOS font routines and data

; Put a large character to the kernel con buffer
; Input:  
;    c='char'

PUTC_L:
    ld hl, (KERNEL_CON_Y)
    call CON_GET_STATUS
    ld d, a
    ld a, 7
    add a, d
    cp l
    jr nc, {@}
    ret
@
    jr nz, {@}
    ret
@
    ld a, h
    ld h, 0
    add hl, hl
    add hl, hl
    push hl
    pop de
    add hl, hl
    add hl, de
    ld d, 0
    ld e, a
    add hl, de
    ld de, KERNEL_CON_BUF
    add hl, de
    ld a, c
    ld (hl), a
    ld a, (KERNEL_CON_X)
    inc a
    cp 12
    jr nc, {@}
    ld (KERNEL_CON_X), a
    ret
@
    xor a
    ld (KERNEL_CON_X), a
    call CON_GET_STATUS
    ld d, a
    ld a, 6
    add a, d
    ld c, a
    ld a, (KERNEL_CON_Y)
    cp c
    jr c, {3@}
    jr nz, {3@}
    call CON_GET_WRAP
    cp 0
    jr z, {2@}
    ld hl, KERNEL_CON_BUF+12
    ld de, KERNEL_CON_BUF
    ld c, KERNEL_CON_BUF_LEN-12-12
    call CON_GET_STATUS
    jr z, {@}
    ld a, 12
@
    add a, c
    ld b, 0
    ld c, a
    ldir
    ld hl, KERNEL_CON_BUF_END-12+12
    ld de, KERNEL_CON_BUF_END-11+12
    call CON_GET_STATUS
    jr z, {@}
    ld hl, KERNEL_CON_BUF_END-12-12+12
    ld de, KERNEL_CON_BUF_END-12-11+12
@
    xor a
    ld (hl), a
    ld bc, 11
    ldir
    ret    
@
    ld a, (KERNEL_CON_Y)
    inc a
    ld (KERNEL_CON_Y), a    
    ret
PUTC_L_END:

; Put a large string to kernel con buffer
; input: hl - pointer to string

PUTS_L:
@
    ld a, (hl)
    cp 0
    ret z
    ld c, a
    push hl
    call PUTC_L
    pop hl
    inc hl
    jr {-1@}
PUTS_L_END:


; Update Kernel Console buffer to LCD
; input: a - 1 if status bar shown, 0 otherwise

.define CONU_STATUS 1
.define CONU_NORMAL 0

CONU_L:
    ld hl, KERNEL_CON_BUF
    ld ixh, a
    cp 0
    jr z, {@}
    ld b, KERNEL_CON_BUF_LEN_STATUS
    jr {2@}
@
    ld b, KERNEL_CON_BUF_LEN
@
    ld a, (hl)
    ld c, a
    inc hl
    push hl    
    ld a, ixh
    cp 0
    jr z, {@}
    ld a, KERNEL_CON_BUF_LEN_STATUS
    jr {2@}
@
    ld a, KERNEL_CON_BUF_LEN
@
    sub b
@
    cp 12
    jr c, {@}
    sub 12
    jr {-1@}
@    
    push af
    ld a, ixh
    cp 0
    jr z, {@}
    ld a, KERNEL_CON_BUF_LEN_STATUS
    jr {2@}
@
    ld a, KERNEL_CON_BUF_LEN
@
    sub b
    ld d, 0
@
    cp 12
    jr c, {@}
    sub 12
    inc d
    jr {-1@}
@
    ld a, d
    ld l, a
    pop af

    push af
    push bc
    push de
    push hl
    push ix
    call DPUTC_L
    pop ix
    pop hl
    pop de
    pop bc
    pop af
    pop hl
    djnz {-9@}
    ret
CONU_L_END:


; Put a large character at given location directly to the screen, without loading to the buffer
; Input:  
;    c='char'
;    a='x' (0-11)
;    l='y' (0-6)


DPUTC_L:
    push hl
    push af
    ld ix, DATA_FONT_LARGE
    ld h, 0
    ld a, c
    ld l, a
    add hl, hl
    add hl, hl
    add hl, hl
    ex de, hl
    add ix, de

    ld hl, KERNEL_LCD_BUF
    pop af
    ld d, 0
    ld e, a
    add hl, de

    pop bc
    ld a, c
    add a, a
    add a, a
    add a, a
    ld de, 12
    cp 0
    jr z, {2@}
    ld b, a
@
    add hl, de
    djnz {-1@}
@
    ld b, 8
@
    ld a, (ix)
    ld (hl), a
    inc ix
    add hl, de
    djnz {-1@}
    ret
DPUTC_L_END:













; Put a character to the kernel con buffer
; Input:  
;    c='char'

PUTC_S:
    ld hl, (KERNEL_CON_Y2)
    call CON_GET_STATUS
    ld d, a
    ld a, 9
    add a, d
    cp l
    jr nc, {@}
    ret
@
    jr nz, {@}
    ret
@
    ld a, h
    ld h, 0
    add hl, hl
    add hl, hl
    add hl, hl
    push hl
    pop de
    add hl, hl
    add hl, de
    ld d, 0
    ld e, a
    add hl, de
    ld de, KERNEL_CON_BUF2
    add hl, de
    ld a, c
    ld (hl), a
    ld a, (KERNEL_CON_X2)
    inc a
    cp 24
    jr nc, {@}
    ld (KERNEL_CON_X2), a
    ret
@
    xor a
    ld (KERNEL_CON_X2), a
    call CON_GET_STATUS
    ld d, a
    ld a, 8
    add a, d
    ld c, a
    ld a, (KERNEL_CON_Y2)
    cp c
    jr c, {3@}
    jr nz, {3@}
    call CON_GET_WRAP
    cp 0
    jr z, {2@}
    ld hl, KERNEL_CON_BUF2+24
    ld de, KERNEL_CON_BUF2
    ld c, KERNEL_CON_BUF2_LEN-24-24
    call CON_GET_STATUS
    jr z, {@}
    ld a, 24
@
    add a, c
    ld b, 0
    ld c, a
    ldir
    ld hl, KERNEL_CON_BUF2_END-24+24
    ld de, KERNEL_CON_BUF2_END-23+24
    call CON_GET_STATUS
    jr z, {@}
    ld hl, KERNEL_CON_BUF2_END-24-24+24
    ld de, KERNEL_CON_BUF2_END-24-23+24
@
    xor a
    ld (hl), a
    ld bc, 23
    ldir
    ret    
@
    ld a, (KERNEL_CON_Y2)
    inc a
    ld (KERNEL_CON_Y2), a    
    ret
PUTC_S_END:

; Put a string to kernel con buffer
; input: hl - pointer to string

PUTS_S:
@
    ld a, (hl)
    cp 0
    ret z
    ld c, a
    push hl
    call PUTC
    pop hl
    inc hl
    jr {-1@}
PUTS_S_END:


; Update Kernel Console buffer to LCD
; input: a - 1 if status bar shown, 0 otherwise

CONU_S:
    ld hl, KERNEL_CON_BUF2
    ld ixh, a
    cp 0
    jr z, {@}
    ld b, KERNEL_CON_BUF2_LEN_STATUS
    jr {2@}
@
    ld b, KERNEL_CON_BUF2_LEN
@
    ld a, (hl)
    ld c, a
    inc hl
    push hl    
    ld a, ixh
    cp 0
    jr z, {@}
    ld a, KERNEL_CON_BUF2_LEN_STATUS
    jr {2@}
@
    ld a, KERNEL_CON_BUF2_LEN
@
    sub b
@
    cp 24
    jr c, {@}
    sub 24
    jr {-1@}
@    
    push af
    ld a, ixh
    cp 0
    jr z, {@}
    ld a, KERNEL_CON_BUF2_LEN_STATUS
    jr {2@}
@
    ld a, KERNEL_CON_BUF2_LEN
@
    sub b
    ld d, 0
@
    cp 24
    jr c, {@}
    sub 24
    inc d
    jr {-1@}
@
    ld a, d
    ld l, a
    pop af

    push af
    push bc
    push de
    push hl
    push ix
    call DPUTC_S
    pop ix
    pop hl
    pop de
    pop bc
    pop af
    pop hl
    djnz {-9@}
    ret
CONU_S_END:


; Put a character at given location directly to the screen, without loading to the buffer
; Input:  
;    c='char'
;    a='x' (0-23)
;    l='y' (0-9)


DPUTC_S:
    push af
    push hl
    ld ix, DATA_FONT_SMALL
    ld h, 0
    ld a, c
    ld l, a
    add hl, hl
    push hl
    pop de
    add hl, hl
    add hl, de
    ex de, hl
    add ix, de
    pop hl
    ld a, l
    add a, a
    add a, a
    add a, l
    add a, l
    ld l, a
    pop af
    add a, a
    add a, a
    ld b, 6
    ld c, 1
    call SPRITE_PUT_LARGE
    ret
DPUTC_END_S:

; get current flag
; output: a - 0 if reset, 1 if set

CON_GET_SIZE:
    xor a
    push hl
    ld hl, KERNEL_CON_FLAGS
    bit KERNEL_CON_FLAG_SIZE, (hl)
    pop hl
    jr z, {@}
    inc a
@
    ret
CON_GET_SIZE_END:

CON_GET_STATUS:
    xor a
    push hl
    ld hl, KERNEL_CON_FLAGS
    bit KERNEL_CON_FLAG_STATUS, (hl)
    pop hl
    jr nz, {@}
    inc a
@
    ret
CON_GET_STATUS_END:

CON_GET_WRAP:
    xor a
    push hl
    ld hl, KERNEL_CON_FLAGS
    bit KERNEL_CON_FLAG_WRAP, (hl)
    pop hl
    jr z, {@}
    inc a
@
    ret
CON_GET_WRAP_END:


;
;
;            ONES THAT SHOULD BE EXTERNALLY CALLED FOR REALZ:
;
;
;


CONU:
    xor a
    ld hl, KERNEL_CON_FLAGS
    bit KERNEL_CON_FLAG_STATUS, (hl)
    jr z, {@}
    inc a
@
    ld b, a
    call CON_GET_SIZE
    cp 0
    ld a, b
    jr nz, {@}
    call CONU_S
    ret
@
    call CONU_L
    ret
CONU_END:



PUTC:
    call CON_GET_SIZE
    cp 0
    jr nz, {@}
    call PUTC_S
    ret
@
    call PUTC_L
    ret
PUTC_END:


PUTS:
    push hl
    call CON_GET_SIZE
    pop hl
    cp 0
    jr nz, {@}
    call PUTS_S
    ret
@
    call PUTS_L
    ret
PUTS_END:


DPUTC:
    push af
    push hl
    call CON_GET_SIZE
    pop hl
    cp 0
    jr nz, {@}
    pop af
    call DPUTC_S
    ret
@
    pop af
    call DPUTC_L
    ret
DPUTC_END:

CON_NL_S:
    ld a, 23
    ld (KERNEL_CON_X2), a
    ld c, ' '
    call PUTC_S
    ret
CON_NL_S_END:

 

Basic LCD driver:

; NucleoOS LCD driver code

    ; TODO: advanced LCD functions


    ; command write codes

    .define LCD_CMD_6BITMODE $00
    .define LCD_CMD_8BITMODE $01

    .define LCD_CMD_UNHOOK $02
    .define LCD_CMD_REHOOK $03

    .define LCD_CMD_XAUTODEC $04
    .define LCD_CMD_XAUTOINC $05
    .define LCD_CMD_YAUTODEC $06
    .define LCD_CMD_YAUTOINC $07

    .define LCD_CMD_POWERSUPPLYENHANCEMENT1 $08
    .define LCD_CMD_POWERSUPPLYENHANCEMENT2 $09
    .define LCD_CMD_POWERSUPPLYENHANCEMENT3 $0A
    .define LCD_CMD_POWERSUPPLYENHANCEMENT4 $0B

    .define LCD_CMD_POWERSUPPLYLEVEL1 $10
    .define LCD_CMD_POWERSUPPLYLEVEL2 $11
    .define LCD_CMD_POWERSUPPLYLEVEL3 $12
    .define LCD_CMD_POWERSUPPLYLEVEL4 $13

    .define LCD_CMD_CANCELTESTMODE $18
    .define LCD_CMD_ENTERTESTMODE $1C

    ; command read code masks

    .define LCD_CMD_MASK_AUTOINC %00000001
    .define LCD_CMD_MASK_AUTODEC %00000010
    .define LCD_CMD_MASK_DISPLAYREHOOKED %00100000
    .define LCD_CMD_MASK_SENDING8BITS %01000000
    .define LCD_CMD_MASK_LCDBUSY %10000000


; Send LCD command
; input: a - command codes

LCD_SEND_CMD:
    call LCD_WAIT
    out (PORT_LCD_COMMAND), a
    ret
LCD_SEND_CMD_END:

; wait until LCD is ready

LCD_WAIT:
    push af
    @
        in a, (PORT_LCD_COMMAND)
        and LCD_CMD_MASK_LCDBUSY
        cp 0
        jp nz, {-1@}
    pop af
    ret
LCD_WAIT_END:

; send LCD data at current byte
; input: a - byte of data

LCD_SEND_BYTE:
    call LCD_WAIT
    out (PORT_LCD_DATA), a
    ret
LCD_SEND_BYTE_END:

; Set LCD row
; input: a - row number

LCD_SET_ROW:
    call LCD_WAIT
    add a, $80
    call LCD_SEND_CMD
    ret
LCD_SET_ROW_END:

; Set LCD column
; input: a - column number

LCD_SET_COLUMN:
    call LCD_WAIT
    add a, $20
    call LCD_SEND_CMD
    ret
LCD_SET_COLUMN_END:

; Set LCD contrast
; input: a - contrast (0-63)

LCD_SET_CONTRAST:
    call LCD_WAIT
    add a, $C0
    call LCD_SEND_CMD
    ret
LCD_SET_CONTRAST_END:

; Clear LCD screen

LCD_CLEAR:

    ld a, LCD_CMD_XAUTOINC
    call LCD_SEND_CMD
    ld d, 12
    ld b, 64
    ld e, 0
@
    @
    call LCD_WAIT
    xor a
    call LCD_SEND_BYTE
    djnz {-2@}
@
    ld b, 64
    inc e
    ld a, e
    call LCD_SET_COLUMN
    ld a, d
    dec a
    ld d, a
    cp 0
    jp nz, {-3@}    
    ret
LCD_CLEAR_END:


; Update LCD from address
; input: hl - buffer address

LCD_UPDATE:
    ld a, LCD_CMD_XAUTOINC
    call LCD_SEND_CMD
    ld hl, KERNEL_LCD_BUF
    ld c,$10
    ld a,$80
@
    in f,(c)
    jp m,{-1@}
    out ($10),a
    ld de,12
    ld a,$20
@
    in f,(c)
    jp m,{-1@}
    out ($10),a
    push af
    ld b,64
@
    ld a,(hl)
@
    in f,(c)
    jp m,{-1@}
    out ($11),a
    add hl,de
    djnz {-2@}
    pop af
    dec h
    dec h
    dec h
    inc hl
    inc a
    cp $2c
    jp nz,{-3@}
    ret
LCD_UPDATE_END:

 

Boot sequencer:

; NucleoOS boot sequence code segment
; binds all setup, reset detection, etc. here

__BOOT_SEQUENCE:


    ; TODO: check if RST 00h was called from a process, or if this is an actual reset


.include "memory_setup.z80"
.include "driver_setup.z80"


    ei

    ld hl, KERNEL_CON_FLAGS
    res KERNEL_CON_FLAG_SIZE, (hl)        ; small text
    res KERNEL_CON_FLAG_STATUS, (hl)    ; no status bar space
    set KERNEL_CON_FLAG_WRAP, (hl)        ; console wrapping


    call LCD_CLEAR
    call LCD_UPDATE
    ld hl, boot_str_1
    call PUTS
    call CONU
    call LCD_UPDATE
    ld ixh, 8
    call HARD_WAIT
    call LCD_BUF_CLEAR
    ld hl, boot_str_2
    call PUTS
    call CONU
    call LCD_UPDATE
    ld ixh, 3
    call HARD_WAIT
    call LCD_BUF_CLEAR
    in a, ($15)
    cp 55
    jr z, {@}
    ld c, '8'
    call PUTC
    jr {2@}
@
    ld c, '3'
    call PUTC
@
    ld hl, boot_str_2a
    call PUTS
    in a, ($02)
    rlca
    jp nc, {@}
    and $40
    jp z, {2@}
    in a, ($21)
    and $03
    jp z, {3@}
    jp nz, {4@}
@     ;Regular83Plus
@     ;Silver83Plus
    ld hl, boot_str_2bc
    call PUTS
    call CONU
    call LCD_UPDATE
    call LCD_BUF_CLEAR
    jr $
@     ;Regular84Plus
    ld hl, boot_str_2ba
    call PUTS
    call CONU
    call LCD_UPDATE
    call LCD_BUF_CLEAR
    jr {+}
@     ;Silver84Plus
    ld hl, boot_str_2bb
    call PUTS
+

    call STACKTRACE
    call CONU
    call LCD_UPDATE
    call LCD_BUF_CLEAR

    jr $

__BOOT_SEQUENCE_END:

boot_str_1:
 .db "**** NucleoOS  Boot ****",0
 boot_str_2:
 .db "detecting memory...      ",0
 boot_str_2a:
 .db " RAM pages detected    ",0
 boot_str_2ba:
 .db "64 ROM pages detected  ",0
 boot_str_2bb:
 .db "128 ROM pages detected ",0
 boot_str_2bc:
 .db "err: UNSUPPORTED MODEL Failure to boot device.",0

Memory protection and intialization:

 

; NucleoOS boot sequence code segment
; setup memory pages for basic execution

    ld sp, $0000
    ld a, HW_TIMER_SPEED_FAST
    out (PORT_TIMER_SPEED), a ; this also sets up memory in mode 1

    call GET_PRIV_PAGE        ; priv page into 4000-7FFF
    out (PORT_BANK_A), a

    ld a, $80                ; RAM page 0 into 8000-BFFF (Process RAM)
    out (PORT_BANK_, a

    ld a, $01                ; RAM page 1 into C000-FFFF (Kernel RAM)
    out (PORT_BANK_C), a

    xor a
    call CPU_SET_SPEED


    call UNLOCK_FLASH
        ; Remove RAM Execution Protection
        xor a
        out ($25), a
        dec a
        out ($26), a

        out ($23), a
        out ($22), a
    call LOCK_FLASH

    xor a
    out ($28), a
    out ($27), a


    ld a, %00000000
    out (PORT_INT_MASK), a

    ld hl, $C000
    ld (hl), 0
    ld de, $C001
    ld bc, $7FFF
    ldir

 

Various conglomerated define files:

 

; NucleoOS buffer addresses

; kernel RAM page ($01) buffers:

    ; Kernel LCD buffer:
    .define KERNEL_LCD_BUF $C000
    .define KERNEL_LCD_BUF_LEN 768
    .define KERNEL_LCD_BUF_END $C300

    ; Kernel console buffer (large text)
    .define KERNEL_CON_BUF $C300
    .define KERNEL_CON_BUF_LEN 96
    .define KERNEL_CON_BUF_LEN_STATUS 84 ; length of usable space when status bar is rendered
    .define KERNEL_CON_BUF_END $C360

    .define KERNEL_CON_Y $C360
    .define KERNEL_CON_X $C361

    ; Kernel console buffer (small text)
    .define KERNEL_CON_BUF2 $C362
    .define KERNEL_CON_BUF2_LEN 240
    .define KERNEL_CON_BUF2_LEN_STATUS 216 ; length of usable space when status bar is rendered
    .define KERNEL_CON_BUF2_END $C452

    .define KERNEL_CON_Y2 $C452
    .define KERNEL_CON_X2 $C453

        .define KERNEL_CON_FLAG_STATUS 0     ; status area will not be allowed to be used (1 - status set)
        .define KERNEL_CON_FLAG_SIZE 1       ; current size of the text shown, decides which buffer to read from (1 is large)
        .define KERNEL_CON_FLAG_INVERT 2     ; inverts all text on rendering if 1
        .define KERNEL_CON_FLAG_ASCII 3        ; 1 if selected all special code page 437 characters will be printed as spaces
        .define KERNEL_CON_FLAG_WRAP 4        ; 1 if wraps text up in console if end of usable space has been breaches

    .define KERNEL_CON_FLAGS $C454

    .define KERNEL_ITOA_LAST $C455

    .define KERNEL_IM1_COUNTER $C475



; NucleoOS equates for timer speeds

.define HW_TIMER_SPEED_SLOWEST (%00000110|MEMORY_MAP_MODE_1) 
.define HW_TIMER_SPEED_SLOW (%00000100|MEMORY_MAP_MODE_1) 
.define HW_TIMER_SPEED_FAST (%00000010|MEMORY_MAP_MODE_1) 
.define HW_TIMER_SPEED_FASTEST (%00000000|MEMORY_MAP_MODE_1) 




; NucleoOS memory modes, pages, violations, etc. defines

.define MEMORY_MAP_MODE_0 %00000000
.define MEMORY_MAP_MODE_1 %00000001

.define MEMORY_ACC_VIOLATION_HANDLE 1
.define MEMORY_ACC_VIOLATION_NO_HANDLE 0

.define MEMORY_ACC_VIOLATION_NONE 0
.define MEMORY_ACC_VIOLATION_LOW 1
.define MEMORY_ACC_VIOLATION_HIGH 2




; NucleoOS port equates

.define PORT_TIMER_SPEED $04
.define PORT_IM1_INT $04
.define PORT_BANK_A $06
.define PORT_BANK_B $07
.define PORT_BANK_C $05
.define PORT_INT_MASK $03
.define PORT_CPU_LOW_POWER $03
.define PORT_LCD_COMMAND $10
.define PORT_LCD_DATA $11
.define PORT_RAM_PROT_LOWER $25
.define PORT_RAM_PROT_UPPER $26
.define PORT_FLASH_PROT_LOWER $22
.define PORT_FLASH_PROT_UPPER $23
.define PORT_CPU_SPEED $20



; NucleoOS versioning defines

.define MAJOR_VERSION $00
.define MINOR_VERSION $01

 

And a lot more to that.

 

Seems I have recovered approximately 10,000 lines of code overally. Wheee! I should totally pick this project up again.

Edited by Ashbad
  • Brohoof 1

b_560_95_1.png

 

What has fanfiction has Ashbad written lately?

We should totally find out by clicking this link.

(Protip, turn on "Show Mature" to see more)

Link to comment
Share on other sites

  • 4 months later...

I am a nub at arduino and have no idea how to code it! can 1 of those people above me plz help me with it on steam @ watamacha? I'm trying to build a tank using a nano, an uno, their respective XBee shields, and a joystick shield for the uno so I can remote control the tank using the uno as the controller and the nano as the reciever. pweez help?


EITHER YOU SHAT YOUR PANTS OR YOU GOT FROSTBITE IN YOUR POOPER


xRHKlvO.png

Link to comment
Share on other sites

I'm not at a computer right now, but when I get to one I will show you the masterpiece that I am coding in GameMaker right now


My OC

 

Stay pony my friends

"And ALWAYS remember...to never forget." - Someone who I'm sure has said this before I did

Link to comment
Share on other sites

What the hell. I guess I'll double bump.

 

 

if room=room0
{
if instance_number(obj_enemy1)<=10
{
if floor(random(25))=1
{
if choose(1,2)=1
{
obj=instance_create(random_range(view_xview,view_xview+832),view_yview,obj_enemy1)
with(obj){gravity=1}
}
else
{
if choose(1,2)=1
{
obj=instance_create(view_xview,random_range(view_yview,view_yview+640),obj_enemy1)
with(obj){hspeed=8; gravity=1}
}
else
{
obj=instance_create(view_xview+832,random_range(view_yview,view_yview+640),obj_enemy1)
with(obj){hspeed=-8; gravity=1}
}
}
}
}
}
if room=room5 || room=room7
{
y=random_range(view_yview[0],960)
if floor(random(50))=1
{
instance_create(choose(0,room_width-32),y,obj_fuckingbird1)
}
}

 

Not very impressive, but I am pretty proud of it. I came up with it myself. It's a code that generates enemies outside of the screen in GML. The first part is for enemies that fall from the skies, and the second is for birds.


My OC

 

Stay pony my friends

"And ALWAYS remember...to never forget." - Someone who I'm sure has said this before I did

Link to comment
Share on other sites

I'll post code later since I'm on my phone atm. I'm currently programming my arduino to read a 32mbit flash memory chip. I plan to store a piece of music on there and play it out through a speaker via a Digital to Analog converter and amplifier. The music is obviously going to be pony related.

 

I have something similar already on my YouTube channel 20samp:

 

EDIT: Wow I'm such an idiot. I tried to create a repository using git and somehow managed to delete everything. Oh well... time to start from scratch XD. I still have the code for the other melody project so I'll share that instead:

/*
  MLPMelody
  
  Based on the Melody example project.
 */
 #include "pitches.h"
 
#define WHOLE 1.0
#define HALF 0.5
#define HALF_DOT 0.75
#define QUARTER 0.25
#define QUARTER_DOT 0.375
#define EIGTH 0.125
#define EIGTH_DOT 0.1875
#define SIXTEENTH 0.0625

float duration = 2000; //~80bpm

// notes in the melody:
int melody[] = {
NOTE_FS5, NOTE_A5, NOTE_FS5, NOTE_E5, NOTE_A5,
NOTE_D5, NOTE_E5, NOTE_D5, NOTE_CS5, NOTE_A4,
NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_E5,
NOTE_D5, 0, NOTE_CS5, NOTE_D5, NOTE_E5, NOTE_D5,
/*NOTE_D5*/ NOTE_FS5, NOTE_FS5, NOTE_FS5, NOTE_FS5, 0, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_FS5, NOTE_E5,
NOTE_D5, 0, NOTE_CS5, NOTE_D5, NOTE_E5, NOTE_D5, 0, NOTE_D5, NOTE_E5,
NOTE_FS5, 0, NOTE_A5, 0, NOTE_FS5, 0, NOTE_E5, NOTE_D5, NOTE_FS5, NOTE_E5,
0, NOTE_D5, NOTE_D5, NOTE_D5, NOTE_D5, NOTE_FS5, NOTE_A5, NOTE_B5, 0, NOTE_A5, NOTE_D5,
NOTE_E5, 0, NOTE_E5, 0, NOTE_E5, NOTE_FS5, NOTE_E5, NOTE_FS5, 0, NOTE_E5, 0,
NOTE_D5, NOTE_E5, 0, NOTE_FS5, NOTE_D5, NOTE_A5, NOTE_A5, NOTE_A5, NOTE_B5, 0, NOTE_A5, NOTE_D5,
NOTE_E5, 0, NOTE_E5, 0, NOTE_E5, NOTE_A5, 0, NOTE_B5, 0, NOTE_A5, NOTE_A5, 0, NOTE_FS5, NOTE_G5,
NOTE_D5, 0, NOTE_CS5, NOTE_D5, NOTE_E5, NOTE_D5, 0, NOTE_D5, NOTE_E5,
NOTE_FS5, NOTE_D5, NOTE_G5, NOTE_FS5, NOTE_E5, 0, NOTE_D5, NOTE_FS5, NOTE_E5, NOTE_D5
/*NOTE_D5*/
};

float noteDurations[] = {
EIGTH, EIGTH, EIGTH, QUARTER, QUARTER_DOT, 
EIGTH, EIGTH, EIGTH, QUARTER, QUARTER_DOT, 
QUARTER, QUARTER, QUARTER, QUARTER,
EIGTH_DOT, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH_DOT, QUARTER_DOT+ 
SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH, EIGTH, EIGTH_DOT,
EIGTH_DOT, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH_DOT, EIGTH_DOT, QUARTER, SIXTEENTH, SIXTEENTH,
EIGTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, SIXTEENTH, EIGTH, QUARTER,
SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, QUARTER, SIXTEENTH,
SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, QUARTER, SIXTEENTH,
SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH_DOT, EIGTH,
SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, SIXTEENTH, EIGTH,
EIGTH_DOT, SIXTEENTH, SIXTEENTH, EIGTH, EIGTH_DOT, EIGTH, QUARTER, SIXTEENTH, SIXTEENTH,
EIGTH, SIXTEENTH, EIGTH, EIGTH, EIGTH, SIXTEENTH, EIGTH, EIGTH, EIGTH, SIXTEENTH +
QUARTER
};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 116; thisNote++) {

    int noteDuration = duration*noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}

void loop() {
  // no need to repeat the melody.
}
Edited by Sam
  • Brohoof 2
Link to comment
Share on other sites

  • 3 weeks later...

Some more GML. I've decided instead of save files for a game, I'll just use a password system. I just made a demo. You're a square that can be 4 different colors (depending on what still frame your sprite is set at. When you die, you get a password, depending on your X and Y coordinates, and what color you were. There are 16 different passwords, since there are only 2 variables, and they each can be 4 different values.

 

This is the code for when you enter a password. I commented it, in case you can't understand it. It'll probably be pretty easy to understand, considering it's GML

 

var a, b, password; //variables, a is the variable for the first character, b is the variable for the second, and password is for the string of the entire password entered

password=get_string("Enter Password:","") //Place where you enter the password

{

    if string_length(password)>2 //If the password entered is less than 2 characters (The length of the password so far)

    {

        show_message("PASSWORD TOO LONG!!!") //Tell the user that the password is too short

        room_restart() //the equivalent of a a repeat loop. The room, and this code, both restart themselves

        exit; //This is necessary. It stopps the code. Without this line, bad things'll happen

    }

    if string_length(password)<2 //If the password entered is more than 2 characters

    {

        show_message("PASSWORD TOO SHORT!!!") //Same

        room_restart() //As

        exit; //Above

    }

    if string_length(password)=2 //If the user enters a 2 character password like they're supposed to

    {

        a=string_char_at(password,1) //Reads the first character in the password

        {

            if a="0"

            {

            global.is=0 //Global.is is a pseudovariable, which stands for image_single, a real variable.

            } //In the Player object's create event, if a password has been entered, image_single=global.is

            else if a="1"

            {

            global.is=1

            }

            else if a="2"

            {

            global.is=2

            }

            else if a="3"

            {

            global.is=3

            }

            else //If the user enters a character other than the ones above

            {

            show_message("INVALID CODE!!!") //INVALID CODE!

            room_restart()

            exit;

            }

        }

        b=string_char_at(password,2) //Reads the second character in the passcode

        {

            if b="a"

            {

            global.px=(room_width/4) //Global.px and global.py are also pseudovariables. They represent the player's x and y coordinates

            global.py=(room_height/4) //The player can spawn at 4 different places. The left corner of the room, the right corner, or the lower left or lower right

            }

            else if b="b"

            {

            global.px=(room_width/4)

            global.py=(room_height*.75) //Can't really divide by 1.33333333333333333...

            }

            else if b="c"

            {

            global.px=(room_width*.75)

            global.py=(room_height/4)

            }

            else if b="d"

            {

            global.px=(room_width*.75)

            global.py=(room_height*.75)

            }

            else //Once again, if the user enters, this time a letter, other than the ones shown above

            {

            show_message("INVALID CODE!!!") //Invalid code is shown to them

            room_restart()

            exit;

            }

        }

    }

    room_goto(rm_main) //If everything works, it goes to the main room, and the player is given where he is supposed to go, and how he is supposed to look

}

I'm pretty proud of it. I thought of it and programmed it entirely by myself.


My OC

 

Stay pony my friends

"And ALWAYS remember...to never forget." - Someone who I'm sure has said this before I did

Link to comment
Share on other sites

  • 2 months later...

@Sam, which Arduino are you using? They all have analog outputs afaik?

Sorry for late reply (don't think the @ tag worked and I haven't been online for a long time). In my video I was using the Arduino Uno. I've recently sold that onto a friend now though and have bought myself an Arduino Mega 2560 instead.

Link to comment
Share on other sites

Sorry for late reply (don't think the @ tag worked and I haven't been online for a long time). In my video I was using the Arduino Uno. I've recently sold that onto a friend now though and have bought myself an Arduino Mega 2560 instead.

Alright. Any updates on that project?

 

 

 


 

On an unrelated note, my team and I got second place during the engineering competition for the robot I built. ( Out of 20~ groups )

 


 

And back on topic, I am currently putting the finishing touches on the new eqtv. ( You can read about that here: http://mlpforums.com/blog/13/entry-4598-a-few-updates-about-myself-and-the-projects-i-am-in-aka-poniverse/ ) 

 

One thing I am particularly fond of is SASS ( which stands for Synthetically Awesome Stylesheets ) and I use a few of it's built-in features to make theme creations for EQTV a breeze. ( At least the boilerplate. ) The theme is created with a command like this:

body {
  // $theme-name,$background-color, $box-color, $link-color, $navbar-color, $primary-nav-color, $secondary-nav-color
  @include theme("twilight", #D19FE3, #B689C8, #662D8A, #263773, #ED438A, #662D8A);

  @include theme("rainbow", #9EDBF9, #77B0E0, #460025, #1E98D3, #672F89, transparent);

  @include theme("fluttershy", #FDF6AF, #FEE78F, #EAD463 , #F3B6CF, white, transparent)

}

After that part you then specify the special rules pertaining to a theme. ( Like images. ) Due to the cascading of the styles they get effectively overwritten.

  • Brohoof 1

I love you! <3

Link to comment
Share on other sites

Alright, I'm an expert at programming and this is what I've been working on for a long time:

 

Create a character;

Some random string crap and symbols ()"&("

MAKE SHIT GO BOOOM

Profit;

 

It's a game btw

Link to comment
Share on other sites

Alright. Any updates on that project?

Haven't worked on anything like that for a while tbh. I have started to build my own 3D printer though which is controlled by my Arduino. I'm sure ponies will be on the list of things to print XD
Link to comment
Share on other sites

Haven't worked on anything like that for a while tbh. I have started to build my own 3D printer though which is controlled by my Arduino. I'm sure ponies will be on the list of things to print XD

 

This is literally the only reason why I want to build one as well. I don't have the space right now, but as soon as I have my own apartment I will try to find a few inches for it :3

 

How big will the printing space be?


I love you! <3

Link to comment
Share on other sites

This is literally the only reason why I want to build one as well. I don't have the space right now, but as soon as I have my own apartment I will try to find a few inches for it :3

 

How big will the printing space be?

200x200mm on the base. not exactly sure how high, although a guess would be about 150mm. I got all the parts for mine from ebay. cost me about £350 in total which would equate to about 540 USD.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Join the herd!

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...