From 7c49bd154136b0cf7b5be9a493cc82537bb217da Mon Sep 17 00:00:00 2001 From: alloncm Date: Thu, 29 Sep 2022 01:12:41 +0300 Subject: [PATCH] Add sound support *Update readme * Add hardware.inc as submodule --- .gitignore | 1 + .gitmodules | 3 ++ Makefile | 2 +- README.md | 26 ++++-------- hardware.inc | 1 + src/bootrom.asm | 107 +++++++++++++++++++++++++++--------------------- 6 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 .gitmodules create mode 160000 hardware.inc diff --git a/.gitignore b/.gitignore index 8deeab7..1183705 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o *.bin +.vscode \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e462b08 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hardware.inc"] + path = hardware.inc + url = https://github.com/gbdev/hardware.inc diff --git a/Makefile b/Makefile index fe52c6f..ece68e0 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 06c2a30..6f72060 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. \ No newline at end of file diff --git a/hardware.inc b/hardware.inc new file mode 160000 index 0000000..8124cf4 --- /dev/null +++ b/hardware.inc @@ -0,0 +1 @@ +Subproject commit 8124cf43bc9a0df31517f20b6e66a073c899ef24 diff --git a/src/bootrom.asm b/src/bootrom.asm index bf278ad..1eb7a99 100644 --- a/src/bootrom.asm +++ b/src/bootrom.asm @@ -1,3 +1,8 @@ +INCLUDE "hardware.inc" + +DEF WAIT_LEN equ 2 +DEF SCROLL_LEN equ 10 + SECTION "main", ROM0[$0] Main:: @@ -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 @@ -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 @@ -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) @@ -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) @@ -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