Permalink
Browse files

- fixed gb.mak, cleaned up includes and added some macros

  • Loading branch information...
1 parent dce2f56 commit 93364ee8cd2396103e3b7b37a8d077f865e5d147 @gilligan committed Mar 28, 2009
Showing with 263 additions and 48 deletions.
  1. +0 −18 include/header.inc
  2. +78 −0 include/macros.inc
  3. +127 −27 {include → lib}/std.asm
  4. +1 −1 src/downtown/Makefile
  5. +56 −1 src/downtown/main.asm
  6. +1 −1 src/gb.mak
View
@@ -1,21 +1,3 @@
-.rombanksize $4000
-.rombanks 4
-
-.memorymap
-SLOTSIZE $4000
-DEFAULTSLOT 1
-SLOT 0 $0000
-SLOT 1 $4000
-.endme
-
-.name "downtown!"
-.ramsize 0
-.emptyfill $00
-.cartridgetype 1
-.computechecksum
-.computecomplementcheck
-.romgbc
-
.BANK 0
.ORG $104
View
@@ -0,0 +1,78 @@
+;
+; wait for vblank to start
+;
+.macro wait_vblank
+@wait:
+ ld a,[STAT]
+ and 1
+ jp z,@wait
+.endm
+
+;
+; stupid macro to do (bc>>n)
+;
+.macro shr16_bc
+ .rept \1
+ srl b
+ rr c
+ .endr
+.endm
+
+;
+; stupid macro to do (bc<<n)
+;
+.macro shl16_bc
+ .rept \1
+ sla c
+ rl b
+ .endr
+.endm
+
+;
+; load_pal [source] [byte-count]
+; NOTE: set BCPS prior to this
+.macro load_pal ;
+ ld hl,\1
+ ld c,\2
+@load_pal:
+ ld a,[hl+]
+ ld [BCPD],a
+ dec c
+ jp nz,@load_pal
+.endm
+
+
+;
+; carry out single DMA transfer
+; [len] bytes from [src] to [dst]
+;
+.macro do_dma_copy ; src,dst,len
+ ld a,>\1
+ ld [HDMA1],a
+ ld a,<\1
+ ld [HDMA2],a
+ ld a,>\2
+ ld [HDMA3],a
+ ld a,<\2
+ ld [HDMA4],a
+ ld a,\3>>4
+ ld [HDMA5],a
+.endm
+
+;
+; wait until [bit] in [reg] is set
+;
+.macro wait_bit_set reg, bit
+@wait_bit:
+ bit reg, bit
+ jp z,@wait_bit
+.endm
+
+;
+; wait until [bit] in [reg] is clear
+;
+.macro wait_bit_clear reg, bit
+@wait_bit:
+ bit reg, bit
+ jp nz, @wait_bit
+.endm
@@ -1,7 +1,133 @@
;
-; standard functions
+; generic functions
;
+; input: [hl] = src palette data
+; [de] = dst palette data
+; c = fade step (0..31)
+; b = number of colors
+fade_white_to_pal:
+
+/*
+ for (int i=0; i<4; i++){
+
+ r = get_red(hl[i]);
+ g = get_green(hl[i]):
+ b = get_blue(hl[i]);
+
+ r += c; if (r>31) r=31;
+ g += c; if (g>31) g=31;
+ b += c; if (b>31) b=31;
+
+ de[i] = compose_pal(r,g,b)
+ }
+
+*/
+
+.equ temp_blue 0
+.equ temp_green 1
+.equ temp_red 2
+
+color_change_lp:
+
+ ld a,[hl]
+ srl a
+ srl a ; a = blue
+ add c ; add color delta
+ bit 5,a
+ jp z,blue_foo
+ ld a,$0f
+blue_foo:
+ ld [SCRATCH+temp_blue],a
+
+ ld a,[hl]
+ sla a
+ sla a
+ sla a
+ ld b,a
+ ld a,[hl+]
+ srl a
+ srl a
+ srl a
+ srl a
+ srl a
+ or b
+ and %11111 ; a = green
+ add c ; add color delta
+ bit 5,a
+ jp z,green_foo
+ ld a,$0f
+green_foo:
+ ld [SCRATCH+temp_green],a
+
+ ld a,[hl+]
+ and %11111 ; a = red
+ add c
+ bit 5,a
+ jp z,red_foo
+red_foo:
+ ld a,$0f
+ ld [SCRATCH+temp_red],a
+
+ ;
+ ; compose R/G/B and store values back
+ ;
+ ld a,[SCRATCH+temp_blue]
+ sla a
+ sla a
+ ld b,a
+ ld a,[SCRATCH+temp_green]
+ srl a
+ srl a
+ srl a
+ and %11
+ ld [de],a ; store upper byte (blue/green)
+ inc de
+
+ ld a,[SCRATCH+temp_green]
+ and %111
+ sla a
+ sla a
+ sla a
+ sla a
+ sla a
+ ld b,a
+ ld a,[SCRATCH+temp_red]
+ or b
+ ld [de],a
+ inc de
+
+ dec b
+ jp nz,color_change_lp
+
+ ret
+
+sprite_load_dma:
+ push af
+ ld a, $C0
+ ldh ($46), A ; $46 == r_dma
+ ld a, $28
+
+- dec a
+ jr nz, -
+ pop af
+ ret
+
+;
+; copies the sprite handler code
+; to $FF80 (has to be executed from there)
+;
+copy_sprite_handler:
+ ld hl,$ff80
+ ld de,sprite_load_dma
+ .rept 12
+ ld a,[hl+]
+ ld [de],a
+ inc a
+ .endr
+ ret
+
+
; wait for scanline
;
; in : b=scanline
@@ -20,13 +146,6 @@ hblank:
jp nz,hblank
ret
-.macro wait_vblank
-@wait:
- ld a,[STAT]
- and 1
- jp z,@wait
-.endm
-
;
; copy bc bytes of memory from [hl] to [de]
;
@@ -92,25 +211,6 @@ read_joypad:
ret ; <- Return from Subroutine
-;
-; stupid macro to do (bc>>n)
-;
-.macro shr16_bc
- .rept \1
- srl b
- rr c
- .endr
-.endm
-
-;
-; stupid macro to do (bc<<n)
-;
-.macro shl16_bc
- .rept \1
- sla c
- rl b
- .endr
-.endm
;
View
@@ -1,4 +1,4 @@
TARGET=main
-SRC=main.asm
+SRC=main.asm part_1.asm
include ../gb.mak
View
@@ -1,5 +1,23 @@
+.include "../../include/memory.inc"
+
.include "../../include/header.inc"
.include "../../include/regs.inc"
+.include "../../include/macros.inc"
+
+
+; ram setup
+
+; $c000-$c0ff : scratchmem
+; $c100- : global ram
+;
+.equ SCRATCH $c000
+
+.enum $C0ff
+ demo_part db
+ vbi_ptr dw
+ lcd_ptr dw
+ tim_ptr dw
+.ende
.bank 0 slot 0
.org $150
@@ -12,17 +30,54 @@ reset:
ld [KEY1],a
stop ; enable double speed
+ nop
+ nop
+ nop
+ nop
+
xor a
ld [SCY],a
ld [SCX],a
ld [LCDC],a
+ ld a,1
+ ld [demo_part],a
+
+mainloop:
-.INCLUDE "../../include/std.asm"
+ ld a,[demo_part]
+ ld ($2000),a
+ jp $4000
+
+ jp mainloop
irq_vbi:
+
+ ld a,[vbi_ptr]
+ ld h,a
+ ld a,[vbi_ptr+1]
+ ld l,a
+ jp hl
+
irq_lcd:
+ ld a,[lcd_ptr]
+ ld h,a
+ ld a,[lcd_ptr+1]
+ ld l,a
+ jp hl
+
irq_tim:
+ ld a,[tim_ptr]
+ ld h,a
+ ld a,[tim_ptr+1]
+ ld l,a
+ jp hl
+
irq_ser:
+ reti
irq_htl:
reti
+
+
+.include "../../lib/std.asm"
+
View
@@ -10,7 +10,7 @@ all: $(TARGET).gbc
$(TARGET).link:
@echo "[objects]" > main.link
- $(foreach obj,$(OBJ),echo $(obj) >> main.link )
+ @echo $(OBJ) | sed -e 's/\ /\n/' >> main.link
$(TARGET).gbc: $(OBJ) $(TARGET).link
$(LD) $(LDFLAGS) main.link $(TARGET).gbc

0 comments on commit 93364ee

Please sign in to comment.