gb_test2

changeset 0:cacfa0888410

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Jan 2019 04:16:47 +0200
parents
children d63782badb6b
files .hgignore Makefile gensine hw.inc logo.png test.asm
diffstat 6 files changed, 219 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Thu Jan 10 04:16:47 2019 +0200
     1.3 @@ -0,0 +1,7 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +^sin\.inc$
     1.7 +\.gb$
     1.8 +^test$
     1.9 +\.tiles$
    1.10 +\.tilemap$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Thu Jan 10 04:16:47 2019 +0200
     2.3 @@ -0,0 +1,26 @@
     2.4 +src = test.asm
     2.5 +obj = test.o
     2.6 +bin = test
     2.7 +img = test.gb
     2.8 +
     2.9 +$(img): $(bin)
    2.10 +	cp $< $@
    2.11 +	rgbfix -v -p 0 $@
    2.12 +
    2.13 +$(bin): $(obj)
    2.14 +	rgblink -o $@ $(obj)
    2.15 +
    2.16 +%.o: %.asm
    2.17 +	rgbasm -o $@ $<
    2.18 +
    2.19 +test.o: test.asm sin.inc logo.tiles logo.tilemap
    2.20 +
    2.21 +.PHONY: clean
    2.22 +clean:
    2.23 +	rm -f $(obj) $(bin) $(img)
    2.24 +
    2.25 +logo.tiles: logo.png
    2.26 +	rgbgfx -T -u -o $@ $<
    2.27 +
    2.28 +sin.inc:
    2.29 +	./gensine >$@
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gensine	Thu Jan 10 04:16:47 2019 +0200
     3.3 @@ -0,0 +1,14 @@
     3.4 +#!/usr/bin/python
     3.5 +
     3.6 +import math
     3.7 +
     3.8 +def main():
     3.9 +    s = 16
    3.10 +    x = 0.0
    3.11 +    dx = 2.0 * math.pi / 256.0
    3.12 +    for i in range(256):
    3.13 +        sx = math.sin(x) * s# + s
    3.14 +        print "\tdb ", int(sx)
    3.15 +        x += dx
    3.16 +
    3.17 +main()
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/hw.inc	Thu Jan 10 04:16:47 2019 +0200
     4.3 @@ -0,0 +1,28 @@
     4.4 +; vi:ft=rgbasm:
     4.5 +REG_LCDC        equ $ff40
     4.6 +REG_STAT        equ $ff41
     4.7 +REG_SCY         equ $ff42
     4.8 +REG_SCX         equ $ff43
     4.9 +REG_LY          equ $ff44
    4.10 +REG_LYC         equ $ff45
    4.11 +REG_BGP         equ $ff47
    4.12 +REG_OBP0        equ $ff48
    4.13 +REG_OBP1        equ $ff49
    4.14 +REG_WY          equ $ff4a
    4.15 +REG_WX          equ $ff4b
    4.16 +
    4.17 +LCDC_BGON       equ $01
    4.18 +LCDC_OBJON      equ $02
    4.19 +LCDC_OBJ16      equ $04
    4.20 +LCDC_BGMAP_9C00 equ $08
    4.21 +LCDC_CHAR_8000  equ $10
    4.22 +LCDC_WON        equ $20
    4.23 +LCDC_WMAP_9C00  equ $40
    4.24 +LCDC_DISPON     equ $80
    4.25 +
    4.26 +STAT_MODE_MASK	equ $03
    4.27 +STAT_LYC	equ $04
    4.28 +STAT_IE_HBLANK	equ $08
    4.29 +STAT_IE_VBLANK	equ $10
    4.30 +STAT_IE_OAM	equ $20
    4.31 +STAT_IE_LYC	equ $40
     5.1 Binary file logo.png has changed
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test.asm	Thu Jan 10 04:16:47 2019 +0200
     6.3 @@ -0,0 +1,144 @@
     6.4 +; vi:ft=rgbasm:
     6.5 +include "hw.inc"
     6.6 +
     6.7 +xoffs_center equ 4
     6.8 +yoffs_center equ 12
     6.9 +
    6.10 +frame_ptr equ $ff80
    6.11 +
    6.12 +section "hdr", ROM0[$100]
    6.13 +        nop
    6.14 +        jp main
    6.15 +
    6.16 +rept $150 - $104
    6.17 +        db 0
    6.18 +endr
    6.19 +
    6.20 +section "text", ROM0
    6.21 +
    6.22 +main:
    6.23 +	call init
    6.24 +
    6.25 +	xor a, a
    6.26 +	ldh [frame_ptr], a
    6.27 +.mainloop:
    6.28 +	ldh a, [REG_LY]
    6.29 +	cp a, 144
    6.30 +	jr c, .wait_hsync
    6.31 +
    6.32 +	; we're in vsync, increment frame counter and wait for the next frame
    6.33 +	ldh a, [frame_ptr]
    6.34 +	inc a
    6.35 +	ldh [frame_ptr], a
    6.36 +.wait_newframe:
    6.37 +	ldh a, [REG_LY]
    6.38 +	cp a, 0
    6.39 +	jr nz, .wait_newframe
    6.40 +
    6.41 +	; scanline code
    6.42 +.wait_hsync:
    6.43 +	ldh a, [REG_STAT]
    6.44 +	and a, STAT_MODE_MASK
    6.45 +	jr nz, .wait_hsync
    6.46 +
    6.47 +	ldh a, [frame_ptr]
    6.48 +	ld d, a
    6.49 +
    6.50 +	xor a, a
    6.51 +	ld b, a
    6.52 +	ldh a, [REG_LY]
    6.53 +	add a, d
    6.54 +	ld c, a
    6.55 +
    6.56 +	ld hl, sintab
    6.57 +	add hl, bc	; hl points to sin value (0-64)
    6.58 +
    6.59 +	ld a, yoffs_center
    6.60 +	add a, [hl]
    6.61 +	ldh [REG_SCY], a
    6.62 +
    6.63 +	; done, wait until we're out of hsync
    6.64 +.wait_endhsync:
    6.65 +	ldh a, [REG_STAT]
    6.66 +	and a, STAT_MODE_MASK
    6.67 +	jr z, .wait_endhsync
    6.68 +
    6.69 +	jr .mainloop 
    6.70 +
    6.71 +
    6.72 +	di
    6.73 +.end:   halt
    6.74 +        nop
    6.75 +        jp .end
    6.76 +
    6.77 +init:
    6.78 +	call wait_vsync
    6.79 +	xor a, a
    6.80 +	ldh [REG_LCDC], a
    6.81 +
    6.82 +	; setup identity palette
    6.83 +	ld a, $1b
    6.84 +	ldh [REG_BGP], a
    6.85 +
    6.86 +
    6.87 +	; copy tiles
    6.88 +	ld hl, $8000
    6.89 +	ld de, tiles
    6.90 +	ld bc, tiles_end - tiles
    6.91 +.copytiles:
    6.92 +	ld a, [de]
    6.93 +	ld [hl+], a
    6.94 +	inc de
    6.95 +	dec bc
    6.96 +	ld a, b
    6.97 +	or c
    6.98 +	jp nz, .copytiles
    6.99 +
   6.100 +	; copy tilemap
   6.101 +	ld hl, $9800
   6.102 +	ld de, tilemap
   6.103 +	ld b, 21
   6.104 +.copymap:
   6.105 +	ld c, 21
   6.106 +.copymaprow:
   6.107 +	ld a, [de]
   6.108 +	inc de
   6.109 +	ld [hl+], a
   6.110 +	dec c
   6.111 +	jr nz, .copymaprow
   6.112 +
   6.113 +	push bc
   6.114 +	ld bc, 11
   6.115 +	add hl, bc
   6.116 +	pop bc
   6.117 +
   6.118 +	dec b
   6.119 +	jr nz, .copymap
   6.120 +
   6.121 +	; center viewport
   6.122 +	ld a, yoffs_center
   6.123 +	ldh [REG_SCY], a
   6.124 +	ld a, xoffs_center
   6.125 +	ldh [REG_SCX], a
   6.126 +
   6.127 +	; configure LCD
   6.128 +	ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON
   6.129 +	ldh [REG_LCDC], a
   6.130 +	ret
   6.131 +
   6.132 +wait_vsync:
   6.133 +	ldh a, [REG_LY]
   6.134 +	cp a, 144
   6.135 +	jr c, wait_vsync
   6.136 +	ret
   6.137 +
   6.138 +section "data", ROM0, align[8]
   6.139 +sintab:
   6.140 +include "sin.inc"
   6.141 +
   6.142 +tiles:
   6.143 +incbin "logo.tiles"
   6.144 +tiles_end:
   6.145 +tilemap:
   6.146 +incbin "logo.tilemap"
   6.147 +tilemap_end: