initial commit master
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 17 Feb 2020 00:14:46 +0000 (02:14 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 17 Feb 2020 00:14:46 +0000 (02:14 +0200)
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
src/defs.inc [new file with mode: 0644]
src/draw.asm [new file with mode: 0644]
src/glyphs.inc [new file with mode: 0644]
src/logo.inc [new file with mode: 0644]
src/tiles.inc [new file with mode: 0644]
src/zxtris.asm [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..84ca4a0
--- /dev/null
@@ -0,0 +1,6 @@
+*.o
+*.bin
+*.rom
+*.tap
+*.swp
+*.lst
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..56648cc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,46 @@
+name = zxtris
+src = $(wildcard src/*.asm)
+obj = $(src:.asm=.o)
+bin = $(name).bin
+rom = $(name).rom
+tap = $(name).tap
+
+AS = vasmz80_oldstyle
+ASFLAGS = -Fvobj
+LD = vlink
+LDFLAGS = -b rawbin1
+
+.PHONY: all
+all: tap rom
+
+.PHONY: tap
+tap: $(tap)
+
+.PHONY: rom
+rom: $(rom)
+
+$(bin): $(obj)
+       $(LD) -o $@ $(LDFLAGS) -Ttext 28000 $(obj)
+
+$(rom): $(obj)
+       $(LD) -o $@ $(LDFLAGS) -Ttext 0 $(obj)
+
+$(tap): $(bin)
+       appmake +zx -o $@ --org 28000 --blockname $(name) -b $<
+
+%.o: %.asm
+       $(AS) -o $@ $(ASFLAGS) -L $*.lst $< >/dev/null
+
+zxtris.o: zxtris.asm tiles.inc glyphs.inc logo.inc
+
+.PHONY: clean
+clean:
+       rm -f $(bin) $(rom) $(tap) $(obj) $(obj:.o=.lst)
+
+.PHONY: run
+run: $(tap)
+       fuse-sdl $(tap)
+
+.PHONY: program
+program: $(rom)
+       minipro -p 'AT28C16E @DIP24' -s -w $<
diff --git a/src/defs.inc b/src/defs.inc
new file mode 100644 (file)
index 0000000..59fd0b5
--- /dev/null
@@ -0,0 +1,15 @@
+; vi:filetype=z80:
+
+FB_ADDR                equ $4000
+ATTR_ADDR      equ $5800
+ULA_PORT       equ $fe
+
+TILE_EMPTY     equ 0
+TILE_PFIELD    equ 1
+TILE_BLOCK     equ 2
+TILE_CHESS     equ 3
+TILE_LEFT      equ 4
+TILE_RIGHT     equ 5
+TILE_BOT       equ 6
+TILE_BR                equ 7
+TILE_BL                equ 8
diff --git a/src/draw.asm b/src/draw.asm
new file mode 100644 (file)
index 0000000..2022092
--- /dev/null
@@ -0,0 +1,6 @@
+; vi:filetype=z80:
+       section code,"c"
+       global drawbg
+
+drawbg:
+       ret
diff --git a/src/glyphs.inc b/src/glyphs.inc
new file mode 100644 (file)
index 0000000..d4caa4b
--- /dev/null
@@ -0,0 +1,382 @@
+; vi:filetype=z80:
+       section data,"d"
+
+glyph_0:
+       db %00111000
+       db %01001100
+       db %01001100
+       db %01010100
+       db %01100100
+       db %01100100
+       db %00111000
+       db %00000000
+glyph_1:
+       db %00010000
+       db %00110000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00111000
+       db %00000000
+glyph_2:
+       db %00111000
+       db %01000100
+       db %00000100
+       db %00001000
+       db %00010000
+       db %00100000
+       db %01111100
+       db %00000000
+glyph_3:
+       db %00111000
+       db %01000100
+       db %00000100
+       db %00011000
+       db %00000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_4:
+       db %00001000
+       db %00011000
+       db %00101000
+       db %01001000
+       db %01111100
+       db %00001000
+       db %00001000
+       db %00000000
+glyph_5:
+       db %01111100
+       db %01000000
+       db %01111000
+       db %00000100
+       db %00000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_6:
+       db %00111000
+       db %01000100
+       db %01000000
+       db %01111000
+       db %01000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_7:
+       db %01111100
+       db %00000100
+       db %00001000
+       db %00001000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00000000
+glyph_8:
+       db %00111000
+       db %01000100
+       db %01000100
+       db %00111000
+       db %01000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_9:
+       db %00111000
+       db %01000100
+       db %01000100
+       db %00111100
+       db %00000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_colon:
+       db %00000000
+       db %00000000
+       db %00010000
+       db %00000000
+       db %00000000
+       db %00010000
+       db %00000000
+       db %00000000
+glyph_a:
+       db %00010000
+       db %00101000
+       db %00101000
+       db %01000100
+       db %01111100
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_b:
+       db %11111000
+       db %01000100
+       db %01000100
+       db %01111100
+       db %01000010
+       db %01000010
+       db %11111100
+       db %00000000
+glyph_c:
+       db %00111100
+       db %01000010
+       db %01000000
+       db %01000000
+       db %01000000
+       db %01000010
+       db %00111100
+       db %00000000
+glyph_d:
+       db %11111000
+       db %01000100
+       db %01000010
+       db %01000010
+       db %01000010
+       db %01000100
+       db %11111000
+       db %00000000
+glyph_e:
+       db %11111110
+       db %01000010
+       db %01001000
+       db %01111000
+       db %01001000
+       db %01000010
+       db %11111110
+       db %00000000
+glyph_f:
+       db %11111110
+       db %01000010
+       db %01001000
+       db %01111000
+       db %01001000
+       db %01000000
+       db %11100000
+       db %00000000
+glyph_g:
+       db %00111100
+       db %01000010
+       db %01000000
+       db %01001110
+       db %01000010
+       db %01000010
+       db %00111100
+       db %00000000
+glyph_h:
+       db %11101110
+       db %01000100
+       db %01000100
+       db %01111100
+       db %01000100
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_i:
+       db %00111000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00111000
+       db %00000000
+glyph_j:
+       db %00001110
+       db %00000100
+       db %00000100
+       db %01000100
+       db %01000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_k:
+       db %11101100
+       db %01001000
+       db %01010000
+       db %01110000
+       db %01001000
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_l:
+       db %01110000
+       db %00100000
+       db %00100000
+       db %00100000
+       db %00100000
+       db %00100010
+       db %01111110
+       db %00000000
+glyph_m:
+       db %11000110
+       db %01101100
+       db %01101100
+       db %01010100
+       db %01010100
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_n:
+       db %11000110
+       db %01100100
+       db %01010100
+       db %01010100
+       db %01001100
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_o:
+       db %00111100
+       db %01000010
+       db %01000010
+       db %01000010
+       db %01000010
+       db %01000010
+       db %00111100
+       db %00000000
+glyph_p:
+       db %11111000
+       db %01000100
+       db %01000100
+       db %01111000
+       db %01000000
+       db %01000000
+       db %11100000
+       db %00000000
+glyph_q:
+       db %00111100
+       db %01000010
+       db %01000010
+       db %01000010
+       db %01001010
+       db %01000100
+       db %00111010
+       db %00000000
+glyph_r:
+       db %11111000
+       db %01000100
+       db %01000100
+       db %01111000
+       db %01001000
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_s:
+       db %00111100
+       db %01000010
+       db %01000000
+       db %00111100
+       db %00000010
+       db %01000010
+       db %01111100
+       db %00000000
+glyph_t:
+       db %11111110
+       db %10010010
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00010000
+       db %00111000
+       db %00000000
+glyph_u:
+       db %11101110
+       db %01000100
+       db %01000100
+       db %01000100
+       db %01000100
+       db %01000100
+       db %00111000
+       db %00000000
+glyph_v:
+       db %11101110
+       db %01000100
+       db %01000100
+       db %01000100
+       db %00101000
+       db %00101000
+       db %00010000
+       db %00000000
+glyph_w:
+       db %11101110
+       db %01000100
+       db %01000100
+       db %01010100
+       db %01010100
+       db %00101000
+       db %00101000
+       db %00000000
+glyph_x:
+       db %11101110
+       db %01000100
+       db %00101000
+       db %00010000
+       db %00101000
+       db %01000100
+       db %11101110
+       db %00000000
+glyph_y:
+       db %11101110
+       db %01000100
+       db %00101000
+       db %00111000
+       db %00010000
+       db %00010000
+       db %00111000
+       db %00000000
+glyph_z:
+       db %11111110
+       db %10000100
+       db %00001000
+       db %00010000
+       db %00100000
+       db %01000010
+       db %11111110
+       db %00000000
+
+glyph_caps:
+       db %01100000
+       db %10000000
+       db %10000000
+       db %10000111
+       db %01101000
+       db %00000110
+       db %00000001
+       db %00001110
+;glyph_spc:
+;      db %01100000
+;      db %10000000
+;      db %01011000
+;      db %00110101
+;      db %11011010
+;      db %00010010
+;      db %00010010
+;      db %00000001
+glyph_spc:
+       db %00000000
+       db %00000000
+       db %00000000
+       db %00000000
+       db %00000000
+       db %00000000
+       db %10000001
+       db %11111111
+glyph_symb:
+       db %01100000
+       db %10000000
+       db %01100000
+       db %00010110
+       db %11101000
+       db %00000110
+       db %00000001
+       db %00001110
+glyph_enter:
+       db %00000000
+       db %00000000
+       db %00100001
+       db %01100001
+       db %11111111
+       db %01100000
+       db %00100000
+       db %00000000
diff --git a/src/logo.inc b/src/logo.inc
new file mode 100644 (file)
index 0000000..f20984a
--- /dev/null
@@ -0,0 +1,20 @@
+; vi:filetype=z80:
+       section data,"d"
+
+logo:
+       db $3f,$fe,$fc,$fc,$00,$00,$00
+       db $3f,$fe,$fc,$fc,$00,$00,$00
+       db $3f,$fe,$38,$70,$00,$00,$00
+       db $3c,$1c,$38,$70,$00,$00,$00
+       db $30,$30,$1c,$e0,$00,$00,$00
+       db $00,$74,$1c,$e2,$00,$00,$04
+       db $00,$e4,$8f,$c2,$00,$00,$04
+       db $00,$e9,$00,$44,$00,$24,$08
+       db $01,$ca,$39,$14,$30,$e9,$78
+       db $03,$ce,$45,$27,$49,$4e,$88
+       db $06,$11,$48,$cc,$8a,$48,$98
+       db $0e,$91,$33,$b9,$92,$d8,$b0
+       db $1e,$61,$fc,$de,$6f,$e8,$d0
+       db $3f,$0c,$03,$10,$00,$00,$00
+       db $3f,$fe,$f5,$44,$00,$00,$00
+       db $3f,$fe,$f6,$7c,$00,$00,$00
diff --git a/src/tiles.inc b/src/tiles.inc
new file mode 100644 (file)
index 0000000..0cfce18
--- /dev/null
@@ -0,0 +1,60 @@
+; vi:filetype=z80:
+       section data,"d"
+
+tiles:
+tile_empty:
+       dd $0,$0
+
+tile_pfield:
+       dd $ffffffff, $ffffffff
+
+tile_block:
+       db %11111111
+       db %11111110
+       db %11000110
+       db %11011110
+       db %11011110
+       db %11111110
+       db %11111110
+       db %10000000
+
+tile_chess:
+       db $55,$aa,$55,$aa
+       db $55,$aa,$55,$aa
+
+tile_side_left:
+       db %01010000
+       db %10101000
+       db %01010000
+       db %10101000
+       db %01010000
+       db %10101000
+       db %01010000
+       db %10101000
+
+tile_side_right:
+       db %01110101
+       db %01101010
+       db %01110101
+       db %01101010
+       db %01110101
+       db %01101010
+       db %01110101
+       db %01101010
+
+tile_side_bottom:
+       db $00
+       db $ff, $ff
+       db $aa, $55, $aa, $55, $aa
+
+tile_side_br:
+       db %01110101
+       db %11101010
+       db %11110101
+       db $aa, $55, $aa, $55, $aa
+
+tile_side_bl:
+       db %01010000
+       db %10101011
+       db %01010111
+       db $aa, $55, $aa, $55, $aa
diff --git a/src/zxtris.asm b/src/zxtris.asm
new file mode 100644 (file)
index 0000000..651f894
--- /dev/null
@@ -0,0 +1,232 @@
+; vi:filetype=z80:
+       section code,"c"
+
+       include defs.inc
+
+main:
+       call init
+
+       ld hl, FB_ADDR + 25
+       call draw_logo
+       call drawbg
+
+.mainloop:
+       jr .mainloop
+
+init:
+       ; setup attributes
+       ld hl, ATTR_ADDR
+       ld a, $47
+       ld b, 24
+.attry:        ld c, 32
+.attrx:        ld (hl), a
+       inc hl
+       dec c
+       jr nz, .attrx
+       dec b
+       jr nz, .attry
+
+       ; clear screen
+       ld hl, FB_ADDR
+       xor a
+       ld b, 192
+.clry: ld c, 32
+.clrx: ld (hl), a
+       inc hl
+       dec c
+       jr nz, .clrx
+       dec b
+       jr nz, .clry
+
+       ; set border
+       out (ULA_PORT), a
+       
+       ret
+
+; expects X -> c, Y -> b, returns in de
+calc_cell_addr:
+       push af
+       sla b
+       sla b           ; change from blocks to pixels
+       sla b
+       ; construct low address byte -> e
+       ld a, b         ; start with Y
+       sla a
+       sla a
+       and $e0         ; keep top 3 bits
+       ld e, a         ; move into e
+       ld a, c         ; a <- X
+       and $1f         ; keep low 5 bits
+       or e            ; combine with Y bits
+       ld e, a         ; move the result back to e
+       ; construct high address byte -> d
+       ld a, b         ; start with Y again
+       sra a
+       sra a
+       sra a
+       and $18         ; keep bits 3 and 4
+       ld d, a         ; keep it in d
+       ld a, b         ; grap Y one more time
+       and $7          ; keep low 3 bits of Y in a
+       or d            ; combine with Y6-Y7
+       ld bc, FB_ADDR
+       or b            ; combine with high byte of fb address
+       ld d, a         ; move result back to d
+       pop af
+       ret
+
+       ; hl: dest
+draw_logo:
+       push hl
+       ld de, logo
+       ld b, 16
+.logoy:        ld c, 7
+       push bc
+.logox: ld a, (de)
+       ld (hl), a
+       inc de
+       inc l
+       dec c
+       jr nz, .logox
+       ld bc, 7
+       sbc hl, bc
+       inc h
+
+       ld a, h
+       and $e7
+       ld h, a 
+       and $7
+       jr nz, .skipinc
+       ld a, l
+       add $20
+       ld l, a
+.skipinc:
+       pop bc
+       dec b
+       jr nz, .logoy
+       pop hl
+
+       ; attr
+       ld a, h
+       srl a
+       srl a
+       srl a
+       or $58
+       ld h, a
+       ld a, $42
+
+       push hl
+       pop ix
+       ld b, 7
+.sattr:        ld (ix), a
+       ld (ix + 32), a
+       inc ix
+       dec b
+       jr nz, .sattr
+       ret
+
+       ; de: dest
+       ; a: char
+putchar:
+       ; is it a digit?
+       sub '0'
+       ret c
+       cp 11
+       jr nc, .notdigit
+       push bc
+       ld bc, glyph_0
+       jr .common
+.notdigit:
+       ; is it A-Z ?
+       sub 'A'-'0'
+       ret c
+       cp 30
+       ret nc
+       push bc
+       ld bc, glyph_a
+.common:
+       push de
+       push hl
+       sla a
+       sla a
+       sla a
+       ld h, 0
+       ld l, a
+       add hl, bc
+       ld c, 8
+.chartop:
+       ld a, (hl)
+       ld (de), a
+       inc d
+       inc hl
+       dec c
+       jr nz, .chartop
+       pop hl
+       pop de
+       pop bc
+       ret
+
+       ; de: dest
+       ; hl: str
+putstr:
+       push de
+       push bc
+.loop: xor a
+       ld b, (hl)
+       cp b
+       jr z, .done
+       ld a, b
+       call putchar
+       inc hl
+       inc e
+       jr .loop
+.done: pop bc
+       pop de
+       ret
+
+       ; de: dest
+       ; a: number
+putbin8:
+       push de
+       push bc
+       ld b, 8
+.loop: rlca
+       push af
+       and 1
+       add '0'
+       call putchar
+       pop af
+       inc e
+       dec b
+       jr nz, .loop
+       pop bc
+       pop de
+       ret
+
+putbin5:
+       push de
+       push bc
+       ld b, 5
+       rlca
+       rlca
+       rlca
+       jr putbin8.loop
+
+       ; hl: string
+       ; return -> a
+strlen:
+       push hl
+       xor a
+       ld b, a
+.loop: cp (hl)
+       jr z, .done
+       inc hl
+       inc b
+       jr .loop
+.done: ld a, b
+       pop hl
+       ret
+
+       include glyphs.inc
+       include logo.inc
+       include tiles.inc