mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-02 23:30:21 +00:00
working on assembler
This commit is contained in:
parent
09fb489c2d
commit
e29bfb5f7e
@ -42,7 +42,7 @@ ga('send', 'pageview');
|
||||
<li><a class="dropdown-item" href="#" id="item_new_file">New File...</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_share_file">Share File as GitHub Gist...</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_reset_file">Revert to Original...</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_download_file">Download File</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_download_file">Download Source File</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_download_rom">Download ROM Image</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_record_video">Record Video...</a></li>
|
||||
<li class="dropdown dropdown-submenu">
|
||||
|
@ -7,9 +7,10 @@
|
||||
`include "sound_generator.v"
|
||||
`include "cpu16.v"
|
||||
|
||||
module cpu_platform(clk, reset, hsync, vsync, rgb);
|
||||
module cpu_platform(clk, reset, hsync, vsync, hpaddle, vpaddle, rgb);
|
||||
|
||||
input clk, reset;
|
||||
input hpaddle, vpaddle;
|
||||
output hsync, vsync;
|
||||
output [3:0] rgb;
|
||||
|
||||
@ -114,9 +115,12 @@ module cpu_platform(clk, reset, hsync, vsync, rgb);
|
||||
wire [15:0] cpu_ram_addr;
|
||||
wire busy;
|
||||
wire [15:0] cpu_bus;
|
||||
wire [15:0] flags = {11'b0, vsync, hsync, vpaddle, hpaddle, display_on};
|
||||
|
||||
assign cpu_bus = cpu_ram_addr[15]
|
||||
? program_rom[cpu_ram_addr[9:0]]
|
||||
? (cpu_ram_addr == 16'hffff)
|
||||
? flags
|
||||
: program_rom[cpu_ram_addr[9:0]]
|
||||
: ram_read;
|
||||
|
||||
CPU16 cpu(
|
||||
|
@ -5,6 +5,7 @@
|
||||
"reg":{"bits":3, "toks":["ax", "bx", "cx", "dx", "ex", "fx", "sp", "ip"]},
|
||||
"unop":{"bits":3, "toks":["zero","loada","inc","dec","asl","lsr","rol","ror"]},
|
||||
"binop":{"bits":3, "toks":["or","and","xor","mov","add","sub","adc","sbb"]},
|
||||
"imm5":{"bits":5},
|
||||
"imm8":{"bits":8},
|
||||
"imm16":{"bits":16},
|
||||
"rel8":{"bits":8, "iprel":true, "ipofs":1}
|
||||
@ -24,6 +25,7 @@
|
||||
{"fmt":"push ~reg", "bits":["01010",0,"00000","110"]},
|
||||
{"fmt":"pop ~reg", "bits":["01001",0,"00001","110"]},
|
||||
{"fmt":"rts", "bits":["01001","111","00001","110"]},
|
||||
{"fmt":"mov ~reg,[~reg+~imm5]", "bits":["01001",0,2,1]},
|
||||
{"fmt":"jsr ~reg", "bits":["01110","111","00",0,"110"]},
|
||||
{"fmt":"jsr ~imm16", "bits":["0001110001011000",0,"0111011100100110"]},
|
||||
{"fmt":"jmp ~imm16", "bits":["0001111101011000",0]},
|
||||
|
@ -14,25 +14,44 @@
|
||||
.org 0x8000
|
||||
.len 1024
|
||||
|
||||
.define ScreenBuffer $6000
|
||||
.define PageTable $7e00
|
||||
.define SpriteTable $7f00
|
||||
|
||||
jmp Start
|
||||
|
||||
Start:
|
||||
mov sp,@$6fff
|
||||
mov fx,@InitPageTable
|
||||
jsr fx
|
||||
mov ax,@$1ffe
|
||||
mov ax,@$0700
|
||||
mov fx,@ClearTiles
|
||||
; jsr ex
|
||||
jsr fx
|
||||
mov fx,@DrawMaze
|
||||
jsr fx
|
||||
mov bx,@HelloWorld
|
||||
mov cx,@$1f00
|
||||
mov cx,@$0200
|
||||
mov dx,@$6001
|
||||
mov fx,@WriteString
|
||||
jsr fx
|
||||
mov fx,@ClearSprites
|
||||
jsr fx
|
||||
reset
|
||||
mov fx,@InitSprites
|
||||
jsr fx
|
||||
GameLoop:
|
||||
mov fx,@WaitVSync
|
||||
jsr fx
|
||||
mov fx,@MoveSprites
|
||||
jsr fx
|
||||
jmp GameLoop
|
||||
|
||||
WaitVSync:
|
||||
mov bx,@$FFFF
|
||||
mov ax,[bx]
|
||||
and ax,#16
|
||||
bz WaitVSync
|
||||
rts
|
||||
|
||||
WriteString:
|
||||
mov ax,[bx]
|
||||
bz StringDone
|
||||
@ -45,7 +64,7 @@ StringDone:
|
||||
rts
|
||||
|
||||
DrawMaze:
|
||||
mov dx,@$6040
|
||||
mov dx,@$6080
|
||||
mov bx,@MazeData
|
||||
DrawMazeLoop:
|
||||
mov ax,[bx]
|
||||
@ -65,20 +84,19 @@ ShiftMazeChar:
|
||||
and ex,#$f
|
||||
add ex,@MazeChars
|
||||
mov ex,[ex]
|
||||
or ex,@$1e00
|
||||
; store to video buffer
|
||||
mov [dx],ex
|
||||
inc dx
|
||||
dec fx
|
||||
bnz ShiftMazeChar
|
||||
mov ax,dx
|
||||
sub ax,@$6340
|
||||
sub ax,@$6380
|
||||
bnz DrawMazeLoop
|
||||
rts
|
||||
|
||||
InitPageTable:
|
||||
mov ax,@$6000 ; screen buffer
|
||||
mov bx,@$7e00 ; page table start
|
||||
mov ax,@ScreenBuffer ; screen buffer
|
||||
mov bx,@PageTable ; page table start
|
||||
mov cx,#32 ; 32 rows
|
||||
InitPTLoop:
|
||||
mov [bx],ax
|
||||
@ -88,7 +106,7 @@ InitPTLoop:
|
||||
bnz InitPTLoop
|
||||
rts
|
||||
ClearTiles:
|
||||
mov bx,@$6000
|
||||
mov bx,@ScreenBuffer
|
||||
mov cx,@$3c0
|
||||
ClearLoop:
|
||||
mov [bx],ax
|
||||
@ -97,54 +115,126 @@ ClearLoop:
|
||||
bnz ClearLoop
|
||||
rts
|
||||
ClearSprites:
|
||||
mov bx,@$7f00
|
||||
mov ax,#0
|
||||
mov cx,#$40
|
||||
mov dx,@SpriteTable
|
||||
ClearSLoop:
|
||||
mov ax,[bx]
|
||||
add ax,@$101
|
||||
mov [bx],ax
|
||||
inc bx
|
||||
mov [dx],ax
|
||||
inc dx
|
||||
dec cx
|
||||
bnz ClearSLoop
|
||||
rts
|
||||
InitSprites:
|
||||
mov bx,@SpriteInitData
|
||||
mov cx,#10
|
||||
mov dx,@SpriteTable
|
||||
InitSLoop:
|
||||
mov ax,[bx]
|
||||
mov [dx],ax
|
||||
inc bx
|
||||
inc dx
|
||||
dec cx
|
||||
bnz InitSLoop
|
||||
rts
|
||||
MoveSprites:
|
||||
mov dx,@SpriteTable
|
||||
mov cx,#5
|
||||
MoveSLoop:
|
||||
mov ax,[dx] ; x/y pos
|
||||
mov bx,[dx+1] ; attributes/dir
|
||||
and bx,#3 ; bx = direction (0-3)
|
||||
add bx,@DirectionXY
|
||||
add ax,[bx] ; lookup & add to x/y
|
||||
; make sure we don't collide with wall
|
||||
mov ex,ax
|
||||
add ex,#$08
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex ; divide X by 8
|
||||
and ex,#31
|
||||
mov fx,ex
|
||||
mov ex,ax
|
||||
add ex,@$0800
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex
|
||||
lsr ex ; divide Y by 64
|
||||
and ex,@$ffe0
|
||||
or ex,fx
|
||||
add ex,@ScreenBuffer
|
||||
mov fx,[ex]
|
||||
and fx,@$ff00
|
||||
xor fx,@$0500
|
||||
bz DoNotUpdatePos
|
||||
; update x/y position
|
||||
mov [dx],ax ; store x/y pos
|
||||
inc dx
|
||||
inc dx
|
||||
NextSLoop:
|
||||
dec cx
|
||||
bnz MoveSLoop
|
||||
rts
|
||||
; Choose a new direction
|
||||
DoNotUpdatePos:
|
||||
mov bx,[dx+1] ; attributes/dir
|
||||
inc bx
|
||||
inc dx
|
||||
mov [dx],bx
|
||||
inc dx
|
||||
jmp NextSLoop
|
||||
|
||||
HelloWorld:
|
||||
.string HELLO WORLD
|
||||
.data 0
|
||||
|
||||
SpriteInitData:
|
||||
.data $8363 $3456
|
||||
.data $8373 $4567
|
||||
.data $8383 $5678
|
||||
.data $8373 $1234
|
||||
|
||||
DirectionXY:
|
||||
.data $FFFF
|
||||
.data $0100
|
||||
.data $0001
|
||||
.data $FF00
|
||||
|
||||
MazeData:
|
||||
.data $3111 $1111 $1111 $1114 $3111 $1111 $1111 $1114
|
||||
.data $2000 $0000 $0000 $0002 $2000 $0000 $0000 $0002
|
||||
.data $2031 $1114 $0311 $1402 $2031 $1140 $0311 $1402
|
||||
.data $2051 $1116 $0511 $1605 $6051 $1160 $0511 $1602
|
||||
.data $2031 $1114 $0311 $1402 $2031 $1140 $3111 $1402
|
||||
.data $2d51 $1116 $0511 $1605 $6051 $1160 $5111 $16d2
|
||||
.data $2000 $0000 $0000 $0000 $0000 $0000 $0000 $0002
|
||||
.data $2031 $1114 $0340 $3111 $1114 $0340 $0311 $1402
|
||||
.data $2051 $1116 $0220 $5114 $3116 $0220 $0511 $1602
|
||||
.data $2031 $1114 $0340 $3111 $1114 $0340 $3111 $1402
|
||||
.data $2051 $1116 $0220 $5114 $3116 $0220 $5111 $1602
|
||||
.data $2000 $0000 $0220 $0002 $2000 $0220 $0000 $0002
|
||||
.data $5111 $1114 $0251 $1402 $2031 $1620 $3111 $1116
|
||||
.data $3111 $1116 $0231 $1605 $6051 $1420 $5111 $1114
|
||||
.data $2000 $0000 $0220 $0000 $0000 $0220 $0000 $0002
|
||||
.data $2031 $1114 $0220 $3111 $1114 $0220 $0311 $1402
|
||||
.data $2051 $1116 $0560 $2ccc $ccc2 $0560 $0511 $1602
|
||||
.data $2031 $1114 $0220 $3111 $1114 $0220 $3111 $1402
|
||||
.data $2051 $1116 $0560 $2ccc $ccc2 $0560 $5111 $1602
|
||||
.data $2000 $0000 $0000 $2ccc $ccc2 $0000 $0000 $0002
|
||||
.data $5111 $1114 $0340 $2ccc $ccc2 $0340 $0311 $1116
|
||||
.data $3111 $1116 $0220 $5111 $1116 $0220 $0511 $1114
|
||||
.data $5111 $1114 $0340 $2ccc $ccc2 $0340 $3111 $1116
|
||||
.data $3111 $1116 $0220 $5111 $1116 $0220 $5111 $1114
|
||||
.data $2000 $0000 $0220 $0000 $0000 $0220 $0000 $0002
|
||||
.data $2031 $1114 $0251 $1403 $4031 $1620 $0311 $1402
|
||||
.data $2051 $1116 $0511 $1605 $6051 $1160 $0511 $1602
|
||||
.data $2000 $0000 $0000 $0000 $0000 $0000 $0000 $0002
|
||||
.data $2031 $1114 $0311 $1403 $4031 $1140 $0311 $1402
|
||||
.data $2051 $1116 $0511 $1602 $2051 $1160 $0511 $1602
|
||||
.data $2031 $1114 $0251 $1403 $4031 $1620 $3111 $1402
|
||||
.data $2051 $1116 $0511 $1605 $6051 $1160 $5111 $1602
|
||||
.data $2d00 $0000 $0000 $0000 $0000 $0000 $0000 $00d2
|
||||
.data $2031 $1114 $0311 $1403 $4031 $1140 $3111 $1402
|
||||
.data $2051 $1116 $0511 $1602 $2051 $1160 $5111 $1602
|
||||
.data $2000 $0000 $0000 $0002 $2000 $0000 $0000 $0002
|
||||
.data $5111 $1111 $1111 $1116 $5111 $1111 $1111 $1116
|
||||
|
||||
MazeChars:
|
||||
.data $f9 ; empty
|
||||
.data $c4 $b3 ; horizvert
|
||||
.data $da $bf $c0 $d9 ; corners
|
||||
.data $c3 $c1 $c2 $b4 ; 3-way
|
||||
.data $c5 ; 4-way
|
||||
.data $20 ; empty (no dot)
|
||||
.data $07f9 ; empty
|
||||
.data $05c4 $05b3 ; horizvert
|
||||
.data $05da $05bf $05c0 $05d9 ; corners
|
||||
.data $05c3 $05c1 $05c2 $05b4 ; 3-way
|
||||
.data $05c5 ; 4-way
|
||||
.data $0720 ; empty (no dot)
|
||||
.data $07fe ; power pill
|
||||
|
||||
.data 123 $123
|
||||
.align $10
|
||||
|
@ -48,10 +48,13 @@ var Assembler = function(spec) {
|
||||
var s = rule.fmt;
|
||||
var varlist = [];
|
||||
rule.prefix = s.split(/\s+/)[0];
|
||||
s = s.replace(/\+/g, '\\+');
|
||||
s = s.replace(/\*/g, '\\*');
|
||||
s = s.replace(/\s+/g, '\\s+');
|
||||
s = s.replace(/\[/g, '\\[');
|
||||
s = s.replace(/\]/g, '\\]');
|
||||
s = s.replace(/\./g, '\\.');
|
||||
// TODO: more escapes?
|
||||
s = s.replace(/~\w+/g, function(varname) {
|
||||
varname = varname.substr(1);
|
||||
var v = vars[varname];
|
||||
@ -117,7 +120,7 @@ var Assembler = function(spec) {
|
||||
nbits:width*data.length
|
||||
});
|
||||
for (var i=0; i<data.length; i++) {
|
||||
outwords[ip++ - origin] = data[i];
|
||||
outwords[ip++ - origin] = data[i] & ((1<<width)-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user