To add another project to my long list, I am currently working on a project called Jade. Jade is basically a simulated CPU that doesn't exist in real life (that I am aware of). It is for the TI-83+/84+ calculators and simulates a CPU and set of ports. It uses 256 bytes of editable RAM and 512 bytes of coding space that is the 'ROM'. Unlike the z80 and I am assuming many other processors, it uses no registers. Instead works directly with its RAM. The first 53 bytes of RAM controls such things as the stack pointer, PC, and all of the ports. The latter 128 bytes of RAM are allotted for a stack (though if you know you aren't going to use all 128 bytes, there is no harm in using that for RAM.
There are 8 sets of 5 ports that control sprites. You provide a pointer to the sprite, some coordinates, and the method for drawing.
There are 7 ports for key presses
There is a port that controls which sprites are drawn
There is a port that controls which sets of keys are scanned
There is a status port for turning Jade off or turnign on the LCD update
There is a port that returns which sprites have been drawn
There is a stack pointer
There is a program counter (using 2 bytes).
The first version has been basically abandoned because I have a much better setup and instruction set (I think). The instruction set allows all instructions to be optionally executed if the c or z flag is set, but the base instruction set is:
Code:
To elaborate a little on the syntax (thanks to chickendude for the naming scheme, by the way), lda() will load a byte from one address to another. ldc() will load a constant value to an address. The ideas for jp1(), jp2(), call1(), and call2() were from Runer. I wanted to keep all addreses 1 byte, so before I only had relative jumping and calling. Those instructions now allow for absolute jumps/calls. If you are familiar with z80 assembly, I am sure you can figure out most of the command set.
So my current progress is that I have the instruction set working and I am now working on adding back in the ports (as well as starting to document things). I have had code ready for the past 6 days to test:
Code:
That should allow you to move a sprite around on the screen, once I have the ports added in. The old version was rather unwieldy, and the only screenshot I have to offer is this:
This new version should be faster and smoother. As well, the code is more efficient and so it tends to be smaller (quite a bit smaller, actually).
There are 8 sets of 5 ports that control sprites. You provide a pointer to the sprite, some coordinates, and the method for drawing.
There are 7 ports for key presses
There is a port that controls which sprites are drawn
There is a port that controls which sets of keys are scanned
There is a status port for turning Jade off or turnign on the LCD update
There is a port that returns which sprites have been drawn
There is a stack pointer
There is a program counter (using 2 bytes).
The first version has been basically abandoned because I have a much better setup and instruction set (I think). The instruction set allows all instructions to be optionally executed if the c or z flag is set, but the base instruction set is:
Code:
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 lda() adda() adca() suba() sbca() xora() ora() anda() cpa() inc() rotl() shftl() pusha() pop() inv() ldira()
1 ldc() addc() adcc() subc() sbcc() xorc() orc() andc() cpc() dec() rotr() shftr() pushc() ex() bits() ldirc()
2 ret() setz() setc() togz() togc() jp1() jp2() jrf() jrb() call1() call2() callf() callb()
3
;Duplicate for execution on the c flag condition
4x,5x,6x,7x
;Duplicate for execution on the z flag condition
8x,9x,Ax,Bx
;<not implemented>
Cx,Dx,Ex,Fx
To elaborate a little on the syntax (thanks to chickendude for the naming scheme, by the way), lda() will load a byte from one address to another. ldc() will load a constant value to an address. The ideas for jp1(), jp2(), call1(), and call2() were from Runer. I wanted to keep all addreses 1 byte, so before I only had relative jumping and calling. Those instructions now allow for absolute jumps/calls. If you are familiar with z80 assembly, I am sure you can figure out most of the command set.
So my current progress is that I have the instruction set working and I am now working on adding back in the ports (as well as starting to document things). I have had code ready for the past 6 days to test:
Code:
#include "jade.inc"
.org $00
jrf(start)
sprite:
.db %00111100
.db %01100110
.db %11000011
.db %11100111
.db $FF
.db $FF
.db $FF
.db $FF
start:
ldirc(sprite0,5)
.dw $100+sprite \ .db 0,0,2
ldirc(keyMask,2)
.db 3,1
Loop:
orc(status,1) ;set bit 0 of the status port
KeyLoop:
cpc(key1,kClear) ;Check if clear is pressed
ldcz(status,$80) ;Turn off Jade if the z flag is set by writing 80h to the status port
cpc(key0,-1) ;test if no keys are being pressed
jrbz(KeyLoop)
callf(SpriteWait) ;In case not enough time has passed for the sprite to be drawn
ldc(sUpdate,0) ;Acknowledge the sprite drawing, allowing it to redraw the sprite (XORing twice results in no change)
callf(SpriteWait) ;We need to wait until the sprite is drawn before updating coordinates
cpc(key0,kDown)
incz(sY0)
cpc(key0,kUp)
decz(sY0)
cpc(key0,kLeft)
incz(sX0)
cpc(key0,kRight)
decz(sX0)
ldc(sUpdate,0) ;Acknowledge any sprites drawn, allowing the updated coordinates to be displayed
jrb(Loop)
SpriteWait:
cpa(sUpdate,sMask) ;Check if all of the sprites are drawn
retz()
jrb(SpriteWait)
That should allow you to move a sprite around on the screen, once I have the ports added in. The old version was rather unwieldy, and the only screenshot I have to offer is this:
This new version should be faster and smoother. As well, the code is more efficient and so it tends to be smaller (quite a bit smaller, actually).