Skip to content

Commit

Permalink
Add sound support
Browse files Browse the repository at this point in the history
*Update readme
* Add hardware.inc as submodule
  • Loading branch information
alloncm committed Sep 28, 2022
1 parent 771c5e3 commit 7c49bd1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.o
*.bin
.vscode
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "hardware.inc"]
path = hardware.inc
url = https://github.com/gbdev/hardware.inc
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(TARGET).bin: $(TARGET).o
$(RGBLINK) ${LINKFLAGS} -o $@ $^

$(TARGET).o: $(SRC_DIR)/bootrom.asm
$(RGBASM) $(ASMFLAGS) -o $@ $^
$(RGBASM) $(ASMFLAGS) -i hardware.inc -o $@ $^

.PHONY: clean
clean:
Expand Down
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@ A custom copyright free Gameboy (DMG) bootrom Im making for my own GameBoy emula

![image](https://user-images.githubusercontent.com/25867720/141697694-a24ea751-7c32-41bd-8d90-e36b9b8bb0c9.png)

## Current state

This project is currently WIP.

This my first time writing an actual software in any kind of assembly so any tips and suggestions are welcomed!

I tried to stracture the file in a sensible way but the code is still a bit messy.

### Features
## Features

* Custom boot screen made by me
* Scrolling with a twist
* Scrolling
* Sound

### Future plans

* Cycle accuracy with the original bootrom
* Sound
* Opcode accuracy with the original bootrom

## Building

* Make sure `make` and `rgbds` are installed. (On Windows both can be installed with chocolatey package manager)
* execute `make`
* run `make`

### Platforms
### Build platforms

Built and tested on Windows 10 and Linux (Ubuntu 20.4)
* Windows 10
* Linux (Ubuntu 20.04)

## Tools

Expand All @@ -42,5 +35,4 @@ The gbdev community and especially the awsome gbdev [repo](https://github.com/gb
and especially
* [rgbds](https://github.com/gbdev/rgbds) - for the awsome development toolchain
* [The pandocs](https://gbdev.io/pandocs/) - for the awsome docs
* [Harry Mulders Gameboy dev tools](http://www.devrs.com/gb/hmgd/intro.html) - for the awsome tile design tools.

* [Harry Mulders Gameboy dev tools](http://www.devrs.com/gb/hmgd/intro.html) - for the awsome tile design tools.
1 change: 1 addition & 0 deletions hardware.inc
Submodule hardware.inc added at 8124cf
107 changes: 60 additions & 47 deletions src/bootrom.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
INCLUDE "hardware.inc"

DEF WAIT_LEN equ 2
DEF SCROLL_LEN equ 10

SECTION "main", ROM0[$0]

Main::
Expand All @@ -10,14 +15,6 @@ Main::
ld bc, $2000 ; vram size
call Memset ; init vram

ld hl, $C000 ; ram address
ld bc, $2000 ; ram size
call Memset ; init ram
ld hl, $FE00 ; OAM adress
ld bc, $00A0 ; OAM size
call Memset ; init oam

ld hl, $9A43
ld de, $9A63
ld b, 29
Expand All @@ -35,22 +32,38 @@ Main::
ld a, %10010001 ; Turn lcd and BG on
ld [$ff40], a

.scrollLoop
ld b, $F ; wait time
call Wait
ld a, [$FF42]
inc a
ld [$FF42], a
cp a, $50
jr nz, .scrollLoop
ld c, $5 ; counter for the wait loop, determines the length of the wait
.waitLoop
ld b, $FF
call Wait
dec c
jr nz, .waitLoop
.scrollLoop
ld b, SCROLL_LEN ; wait time
call Wait
ld a, [$FF42]
inc a
ld [$FF42], a
cp a, $50
jr nz, .scrollLoop
; start sound
ld a, %01110111 ; left and right max volume
ld [rNR50], a
ld a, %10001 ; turn channel 1 on
ld [rNR51], a
ld a, $80 ; enable sound
ld [rNR52], a
ld a, %10000000 ; normal wave duty and max len
ld [rNR11], a
ld a, $F1 ; 0xF volume, volume envelope len 1
ld [rNR12], a
ld a, $FF ; 0xFF low freq
ld [rNR13], a
ld a, %11000110 ; start sound, terminated by len, 0x6 high freq
ld [rNR14], a

ld c, WAIT_LEN ; counter for the wait loop, determines the length of the wait
.waitLoop
ld b, $FF ; max wait for Wait proc,
call Wait
dec c
jr nz, .waitLoop

jp FinishBoot

; mut b - wait length
Expand Down Expand Up @@ -81,8 +94,8 @@ SetTilemap:
pop hl
cp a, b
jr nz, SetTilemap
.return
ret
.return
ret

; mut hl - dst (address to set)
; mut bc - len (non zero length)
Expand All @@ -100,9 +113,9 @@ Memset:

ld a, d ; loads a
ret
.continue:
ld a, d ; loads a
jr Memset
.continue:
ld a, d ; loads a
jr Memset

; mut hl - dst (address to copy to)
; mut bc - src (adress to copy from)
Expand Down Expand Up @@ -130,24 +143,24 @@ DecodeLogoToVram:
ld d, a
ld e, a
ld c, 2
.decodeNibleToByte
ld b, 4
.mulBit
rl d
rla
rl e
rla
dec b
jr nz, .mulBit
ld b, 2
.loadValueToVram
ldi [hl], a
ld [hl], 0 ; redunant the vram is already zeroed
inc hl
dec b
jr nz, .loadValueToVram
dec c
jr nz, .decodeNibleToByte
.decodeNibleToByte
ld b, 4
.mulBit
rl d
rla
rl e
rla
dec b
jr nz, .mulBit
ld b, 2
.loadValueToVram
ldi [hl], a
ld [hl], 0 ; redunant the vram is already zeroed
inc hl
dec b
jr nz, .loadValueToVram
dec c
jr nz, .decodeNibleToByte
pop bc
pop de
inc bc
Expand Down

0 comments on commit 7c49bd1

Please sign in to comment.