Commit: 1c20569460b8d84f2b9023209d7063bdcf10ebc9 Author: Vi Grey Date: 2020-08-09 04:19 UTC Summary: Initial Commit Makefile | 35 +++++ README.md | 112 ++++++++++++++ bin/iss-nes.nes | Bin 0 -> 40976 bytes bin/server-linux-386 | Bin 0 -> 6285154 bytes bin/server-linux-amd64 | Bin 0 -> 7062786 bytes bin/server-linux-arm | Bin 0 -> 6288789 bytes bin/server-linux-arm64 | Bin 0 -> 6674070 bytes bin/server-windows-386.exe | Bin 0 -> 6043136 bytes bin/server-windows-amd64.exe | Bin 0 -> 6740480 bytes lua/fceux.lua | 43 ++++++ lua/mesen.lua | 44 ++++++ server/server.go | 92 ++++++++++++ src/controller.asm | 647 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/decompress.asm | 95 ++++++++++++ src/defs.asm | 50 +++++++ src/draw.asm | 255 +++++++++++++++++++++++++++++++ src/graphics/east.atr | Bin 0 -> 64 bytes src/graphics/east.nam | Bin 0 -> 960 bytes src/graphics/tilemap.chr | Bin 0 -> 8192 bytes src/graphics/west.atr | Bin 0 -> 64 bytes src/graphics/west.nam | Bin 0 -> 960 bytes src/include.asm | 67 +++++++++ src/iss-nes.asm | 46 ++++++ src/prg.asm | 141 +++++++++++++++++ src/ram.asm | 68 +++++++++ 25 files changed, 1695 insertions(+) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..998eac4 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +# Copyright (C) 2020, Vi Grey +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +PKG_NAME := iss-nes +CURRENTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +all: + mkdir -p $(CURRENTDIR)bin; \ + cd $(CURRENTDIR)src; \ + asm $(PKG_NAME).asm ../bin/$(PKG_NAME).nes; \ + +clean: + rm -rf -- $(CURRENTDIR)bin; \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..01c35b0 --- /dev/null +++ b/README.md @@ -0,0 +1,112 @@ +# **ISS Tracker for NES** + +International Space Station Tracker for the NES + +_**ISS Tracker for NES was created by Vi Grey (https://vigrey.com) and is licensed under the BSD 2-Clause License.**_ + +### Description: + +This is an NROM NES ROM that tracks the location of the International Space Station in Real-Time. + +### Platforms: +- Linux +- Windows + +------ +## **RUNNING THE NES ROM ON AN EMULATOR** +_**(Source Code Build Instructions are 1 section below)**_ + +This NES ROM has only been successfully tested on two NES emulators, FCEUX for Windows and Mesen for Linux (This will likely work for Mesen on Windows as well). **YOU WILL NEED TO RUN AN INCLUDED LUA SCRIPT AND THE ACCOMPANYING SERVER TO MAKE THIS NES ROM WORK PROPERLY ON AN EMULATOR.** + +### Running the NES ROM: +In the main directory of this project, you will find a `bin` directory. Inside of this directory is a file named `iss-nes.nes`, which can be opened up in FCEUX on Windows or Mesen on Linux (and possibly Windows as well). To make this NES ROM work for real-time tracking of the International Space Station, you will need to run an included lua script and the accompanying server program. + +### Running the Accompanying Server: +In the main directory of this project, you will find a `bin` directory. Inside of this directory are files named `server-linux-386`, `server-linux-amd64`, `server-linux-arm`, `server-linux-arm64`, `server-windows-386.exe`, and `server-windows-amd64.exe`. Depending on whether you are running Linux or Windows, and what CPU architecture you are using, you will need to run the correct server program. This server program will open up a **localhost** connection to port **56502** that the included Lua scripts are able to connect to in order to get the ISS real-time tracking location. + +### Running an Included Lua Script on an Emulator: +In the main directory of this project, you will find a `lua` directory. Inside of that directory is a file called `fceux.lua`, which is used for FCEUX on Windows, and a file called `mesen.lua`, which is used for Mesen. These lua scripts request real-time ISS tracking data (10 bytes of data) from the accompanying server program every frame and displays the information in the NES game while it's running. + +------ +## **BUILDING THE SOURCE CODE** + +### NES ROM Build Dependencies: +- **asm6** (You'll probably have to build asm6 from source. Make sure the asm6 binary is named **asm** and that the binary is executable and accessible in your PATH. The source code can be found at http://3dscapture.com/NES/asm6.zip) +- **gmake** (make) + +### Accompanying Server Build Dependencies: +- **go** + +### Build NES ROM on Linux: +From a terminal, go to the the main directory of this project (the directory this README.md file exists in). You can then build the NES ROM with the following command. + +```sh +make +``` +The resulting NES ROM will be located at `bin/iss-nes.nes` from the main directory. + +### Build NES ROM on Windows: +If you are using Windows, in the command prompt (make sure to have asm6 on your system as `asm.exe`), go to the the `src` directory of this project (the `src` directory this README.md file exists in). You can then build the NES ROM with the following command. + +``` +asm iss-nes.asm ..\bin\iss-nes.nes +``` +Replace the `asm` command with the path to your `asm.exe` command. + +The resulting NES ROM will be located at `bin\iss-nes.nes` from the main directory. + +### Build Accompanying Server on Linux: + +If you are using Linux, go to the `bin` directory of this project (the `bin` directory in the directory this README.md file exists in). You can then build the server binary file with the following command. + +``` +go build ../server/server.go +``` + +The resulting server binary file will be located at `bin/server` from the main directory. + +### Build Accompanying Server on Windows: + +If you are using Windows, go to the `bin` directory of this project (the `bin` directory in the directory this README.md file exists in). You can then build the server binary file with the following command (Assuming you have the `go` command added to your PATH). + +```sh +go build ..\server\server.go +``` + +The resulting server binary file will be located at `bin\server.exe` from the main directory. + +### Cleaning Build Environment (Linux Only): +If you used `make` to build the NES ROM, you can run the following command to clean up the build environment. + +```sh +make clean +``` + +------ + +## **LICENSE** + + Copyright (C) 2020, Vi Grey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS \`\`AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. diff --git a/bin/iss-nes.nes b/bin/iss-nes.nes new file mode 100644 index 0000000..17d9f0b Binary files /dev/null and b/bin/iss-nes.nes differ diff --git a/bin/server-linux-386 b/bin/server-linux-386 new file mode 100755 index 0000000..8481ee2 Binary files /dev/null and b/bin/server-linux-386 differ diff --git a/bin/server-linux-amd64 b/bin/server-linux-amd64 new file mode 100755 index 0000000..0403745 Binary files /dev/null and b/bin/server-linux-amd64 differ diff --git a/bin/server-linux-arm b/bin/server-linux-arm new file mode 100755 index 0000000..554fd4e Binary files /dev/null and b/bin/server-linux-arm differ diff --git a/bin/server-linux-arm64 b/bin/server-linux-arm64 new file mode 100755 index 0000000..b94bfae Binary files /dev/null and b/bin/server-linux-arm64 differ diff --git a/bin/server-windows-386.exe b/bin/server-windows-386.exe new file mode 100755 index 0000000..b7df7ac Binary files /dev/null and b/bin/server-windows-386.exe differ diff --git a/bin/server-windows-amd64.exe b/bin/server-windows-amd64.exe new file mode 100755 index 0000000..4140ee3 Binary files /dev/null and b/bin/server-windows-amd64.exe differ diff --git a/lua/fceux.lua b/lua/fceux.lua new file mode 100644 index 0000000..f003576 --- /dev/null +++ b/lua/fceux.lua @@ -0,0 +1,43 @@ +-- Copyright (C) 2020, Vi Grey +-- All rights reserved. +-- +-- Redistribution and use in source and binary forms, with or without +-- modification, are permitted provided that the following conditions +-- are met: +-- +-- 1. Redistributions of source code must retain the above copyright +-- notice, this list of conditions and the following disclaimer. +-- 2. Redistributions in binary form must reproduce the above copyright +-- notice, this list of conditions and the following disclaimer in the +-- documentation and/or other materials provided with the distribution. +-- +-- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +-- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +-- SUCH DAMAGE. + +local socket = require 'socket.core' + +local HOST = 'localhost' +local PORT = 56502 + +while true do + memory.writebyte(0, 1) + emu.frameadvance() + local tcp = assert(socket.tcp()) + tcp:settimeout(1) + tcp:connect(HOST, PORT) + local s, status, partial = tcp:receive(tcpResLen) + tcp:close() + for i = 10,1,-1 + do + memory.writebyte(1280+i-1, string.byte(partial, i)) + end +end diff --git a/lua/mesen.lua b/lua/mesen.lua new file mode 100644 index 0000000..dd10b2c --- /dev/null +++ b/lua/mesen.lua @@ -0,0 +1,44 @@ +-- Copyright (C) 2020, Vi Grey +-- All rights reserved. +-- +-- Redistribution and use in source and binary forms, with or without +-- modification, are permitted provided that the following conditions +-- are met: +-- +-- 1. Redistributions of source code must retain the above copyright +-- notice, this list of conditions and the following disclaimer. +-- 2. Redistributions in binary form must reproduce the above copyright +-- notice, this list of conditions and the following disclaimer in the +-- documentation and/or other materials provided with the distribution. +-- +-- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +-- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +-- SUCH DAMAGE. + +local socket = require 'socket.core' + +local HOST = 'localhost' +local PORT = 56502 + +function handleFrame() + emu.write(0, 1, emu.memType.cpu) + local tcp = assert(socket.tcp()) + tcp:settimeout(1) + tcp:connect(HOST, PORT) + local s, status, partial = tcp:receive(tcpResLen) + tcp:close() + for i = 10,1,-1 + do + emu.write(1280+i-1, string.byte(partial, i), emu.memType.cpu) + end +end + +emu.addEventCallback(handleFrame, emu.eventType.startFrame) diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..a7ac358 --- /dev/null +++ b/server/server.go @@ -0,0 +1,92 @@ +package main + +import ( + "fmt" + "io/ioutil" + "net" + "net/http" + "time" +) + +const ( + HOST = "localhost" + PORT = "56502" +) + +var ( + positionBuffer []byte + framePosition []byte +) + +func main() { + httpGet() + getFramePosition() + go getISSData() + go getFrameData() + startServer() +} + +func httpGet() { + // Get iss position data from https://vigrey.com/iss + resp, err := http.Get("https://vigrey.com/iss") + if err == nil { + // Get ISS position data from + positionBufferTmp, err := ioutil.ReadAll(resp.Body) + if err == nil { + if len(positionBufferTmp) > 600 { + // If https://vigrey.com/iss provides more than 60 seconds of + // data, set buffer to the response + positionBuffer = positionBufferTmp[:] + } + } + } +} + +func getISSData() { + for { + // Wait 60 seconds before getting data from https://vigrey.com/iss + <-time.After(60 * time.Second) + go httpGet() + } +} + +func getFrameData() { + for { + // Wait 1 seconds before setting new framePosition + <-time.After(1 * time.Second) + go getFramePosition() + } +} + +func getFramePosition() { + if len(positionBuffer) < 10 { + // If the buffer length is less than 10, set framePosition to + // default Epoch time values + framePosition = []byte{0x01, 0x19, 0x70, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00} + } else { + // Set framePosition to the first 10 bytes of buffer + // Remove first 10 bytes of buffer + framePosition = positionBuffer[:10] + positionBuffer = positionBuffer[10:] + } +} + +func startServer() { + // Start server at HOST:PORT + l, err := net.Listen("tcp", HOST+":"+PORT) + if err == nil { + fmt.Println("Server started at " + HOST + ":" + PORT) + defer l.Close() + for { + // Wait for client to connect to server at HOST:PORT + conn, err := l.Accept() + if err == nil { + // Write framePosition (10 bytes) to client and close + // connection + conn.Write(framePosition) + conn.Close() + } + } + } +} diff --git a/src/controller.asm b/src/controller.asm new file mode 100644 index 0000000..b86d16e --- /dev/null +++ b/src/controller.asm @@ -0,0 +1,647 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +; Controller1 to Top Bar Data Protocol +; +; 0 +; HHDD|dddd +; --------- +; |||| |||| +; |||| ++++- Day Ones Digit +; ||++------ Day Tens Digit +; ++-------- Hour Tens Digit +; +; 1 +; YYYY|yyyy +; --------- +; |||| |||| +; |||| ++++- Year Hundreds Digit +; ++++------ Year Thousands Digit +; +; 2 +; YYYY|yyyy +; --------- +; |||| |||| +; |||| ++++- Year Ones Digit +; ++++------ Year Tens Digit +; +; 3 +; hhhh|MMMM +; --------- +; |||| |||| +; |||| ++++- Month Offset Minus 1 +; ++++------ Hour Ones Digit +; +; 4 +; NTTT|tttt +; --------- +; |||| |||| +; |||| ++++- Latitude Ones Place +; |+++------ Latitude Tens Place +; +--------- Longitude Hundreds Digit +; +; 5 +; TTTT|tttt +; --------- +; |||| |||| +; |||| ++++- Latitude Hundredths Place +; ++++------ Latitude Tenths Place +; +; 6 +; NNNN|nnnn +; --------- +; |||| |||| +; |||| ++++- Longitude Ones Place +; ++++------ Longitude Tens Place +; +; 7 +; NNNN|nnnn +; --------- +; |||| |||| +; |||| ++++- Longitude Hundredths Place +; ++++------ Longitude Tenths Place + +; 8 +; TSSS|ssss +; --------- +; |||| |||| +; |||| ++++- Second Ones Digit +; |+++------ Second Tens Digit +; +--------- Latitude Hemisphere +; +; 9 +; NMMM|mmmm +; --------- +; |||| |||| +; |||| ++++- Minute Ones Digit +; |+++------ Minute Tens Digit +; +--------- Longitude Hemisphere + +SetDefaultDate: + lda #$01 + sta controller1 + lda #$19 + sta (controller1 + 1) + lda #$70 + sta (controller1 + 2) + rts + +PollControllerSync: + lda #$00 + sta controllervalid + jsr SetDefaultDate + ldx #$06 + ldy #$08 +PollControllerSyncLatch: + lda #$01 + sta CONTROLLER1 + lda #$00 + sta CONTROLLER1 +PollControllerSyncLoop: + lda CONTROLLER1 + lsr A + ror controllersync + dey + bne PollControllerSyncLoop + lda controllersync + cmp #$FF + beq PollControllerSyncLoopIsFF + cpx #$06 + beq PollControllerSyncContinue + lda #$01 + sta controllervalid + jmp PollControllerSyncContinue +PollControllerSyncLoopIsFF: + ldy #$08 + dex + bne PollControllerSyncLatch +PollControllerSyncContinue: + lda controllervalid + beq PollControllerSyncDone + jsr PollController +PollControllerSyncDone: + jsr PollControllerFinished + rts + +PollController: + ldx #$00 + ldy #$08 +PollControllerLatch: + lda #$01 + sta CONTROLLER1 + lda #$00 + sta CONTROLLER1 +PollController1Loop: + lda CONTROLLER1 + lsr A + rol controller1, x + dey + bne PollController1Loop + ldy #$08 + inx + cpx #$0A + bne PollControllerLatch + rts +PollControllerFinished: + jsr GetDate + jsr GetTime + jsr GetLatitude + jsr GetLongitude + jsr DrawDate + jsr DrawTime + jsr DrawLatitude + jsr DrawLongitude + jsr LatitudeToTmp + jsr LatitudeToYPosition + jsr LongitudeToTmp + jsr LongitudeToXScroll + rts + +GetHour: + lda controller1 + and #%11000000 + asl + rol + rol + sta hour + lda (controller1 + 3) + and #%11110000 + lsr + lsr + lsr + lsr + sta (hour + 1) + rts + +GetMinute: + lda (controller1 + 9) + and #%01110000 + lsr + lsr + lsr + lsr + sta minute + lda (controller1 + 9) + and #%00001111 + sta (minute + 1) + rts + +GetSecond: + lda (controller1 + 8) + and #%01110000 + lsr + lsr + lsr + lsr + sta second + lda (controller1 + 8) + and #%00001111 + sta (second + 1) + rts + +GetDay: + lda controller1 + and #%00110000 + lsr + lsr + lsr + lsr + sta day + lda controller1 + and #%00001111 + sta (day + 1) + rts + +GetYear: + lda (controller1 + 1) + and #%11110000 + lsr + lsr + lsr + lsr + sta year + lda (controller1 + 1) + and #%00001111 + sta (year + 1) + lda (controller1 + 2) + and #%11110000 + lsr + lsr + lsr + lsr + sta (year + 2) + lda (controller1 + 2) + and #%00001111 + sta (year + 3) + rts + +GetMonth: + lda (controller1 + 3) + and #%00001111 + sta month + asl + clc + adc month + sta month + rts + +GetDate: + jsr GetDay + jsr GetYear + jsr GetMonth + rts + +GetTime: + jsr GetHour + jsr GetMinute + jsr GetSecond + +GetLatitude: + lda (controller1 + 4) + and #%01110000 + lsr + lsr + lsr + lsr + sta lat + lda (controller1 + 4) + and #%00001111 + sta (lat + 1) + lda (controller1 + 5) + and #%11110000 + lsr + lsr + lsr + lsr + sta (lat + 2) + lda (controller1 + 5) + and #%00001111 + sta (lat + 3) + lda (controller1 + 8) + and #%10000000 + asl + rol + sta northsouth + rts + + +GetLongitude: + lda (controller1 + 4) + and #%10000000 + asl + rol + sta lon + lda (controller1 + 6) + and #%11110000 + lsr + lsr + lsr + lsr + sta (lon + 1) + lda (controller1 + 6) + and #%00001111 + sta (lon + 2) + lda (controller1 + 7) + and #%11110000 + lsr + lsr + lsr + lsr + sta (lon + 3) + lda (controller1 + 7) + and #%00001111 + sta (lon + 4) + lda (controller1 + 9) + and #%10000000 + asl + rol + sta eastwest + rts + + +DrawDate: + ldy drawBufferOffset + lda #$20 + sta (drawBuffer), Y + iny + lda #$48 + sta (drawBuffer), Y + iny + ldx month + lda Months, X + sta (drawBuffer), Y + iny + inx + lda Months, X + sta (drawBuffer), Y + iny + inx + lda Months, X + sta (drawBuffer), Y + iny + lda #$04 + sta (drawBuffer), Y + iny + lda day + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (day + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$04 + sta (drawBuffer), Y + iny + lda year + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (year + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (year + 2) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (year + 3) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$8E + sta (drawBuffer), Y + iny + sty drawBufferOffset + rts + +DrawTime: + ldy drawBufferOffset + lda #$20 + sta (drawBuffer), Y + iny + lda #$68 + sta (drawBuffer), Y + iny + lda hour + adc #$E1 + sta (drawBuffer), Y + iny + lda (hour + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$E0 + sta (drawBuffer), Y + iny + lda minute + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (minute + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$E0 + sta (drawBuffer), Y + iny + lda second + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (second + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$8E + sta (drawBuffer), Y + iny + sty drawBufferOffset + rts + +DrawLatitude: + ldy drawBufferOffset + lda #$20 + sta (drawBuffer), Y + iny + lda #$88 + sta (drawBuffer), Y + iny + lda lat + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (lat + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$DF + sta (drawBuffer), Y + iny + lda (lat + 2) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (lat + 3) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$04 + sta (drawBuffer), Y + iny + ldx northsouth + lda NorthSouth, X + sta (drawBuffer), Y + iny + lda #$8E + sta (drawBuffer), Y + iny + sty drawBufferOffset + rts + +DrawLongitude: + ldy drawBufferOffset + lda #$20 + sta (drawBuffer), Y + iny + lda #$A7 + sta (drawBuffer), Y + iny + lda lon + beq DrawLongitudeNotHundred + clc + adc #$E1 + jmp DrawLongitudeContinue +DrawLongitudeNotHundred: + lda #$04 +DrawLongitudeContinue: + sta (drawBuffer), Y + iny + lda (lon + 1) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (lon + 2) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$DF + sta (drawBuffer), Y + iny + lda (lon + 3) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda (lon + 4) + clc + adc #$E1 + sta (drawBuffer), Y + iny + lda #$04 + sta (drawBuffer), Y + iny + ldx eastwest + lda EastWest, X + sta (drawBuffer), Y + iny + lda #$8E + sta (drawBuffer), Y + iny + sty drawBufferOffset + rts + +LatitudeToTmp: + lda #$00 + ldx lat +LatitudeToTmpTensLoop: + cpx #$00 + beq LatitudeToTmpTensLoopDone + clc + adc #$0A + dex + jmp LatitudeToTmpTensLoop +LatitudeToTmpTensLoopDone: + clc + adc (lat + 1) + cmp #91 + bcc LatitudeToTmpDone + lda #$00 +LatitudeToTmpDone: + sta tmp + rts + +LatitudeToYPosition: + lda northsouth + bne LatitudeToYPositionSouth + lda #90 + sec + sbc tmp + jmp LatitudeToYPositionContinue +LatitudeToYPositionSouth: + lda tmp + clc + adc #90 +LatitudeToYPositionContinue: + tay + lda (Latitudes), Y + sta $204 + sta $208 + sta $20C + clc + adc #$08 + sta $210 + sta $214 + sta $218 + rts + +LongitudeToTmp: + lda #$00 + ldx lon +LongitudeToTmpHundredsLoop: + beq LongitudeToTmpHundredsLoopDone + clc + adc #100 +LongitudeToTmpHundredsLoopDone: + ldx (lon + 1) +LongitudeToTmpTensLoop: + cpx #$00 + beq LongitudeToTmpTensLoopDone + clc + adc #$0A + dex + jmp LongitudeToTmpTensLoop +LongitudeToTmpTensLoopDone: + clc + adc (lon + 2) + cmp #179 + bcc LongitudeToTmpDone + lda #179 +LongitudeToTmpDone: + sta tmp + rts + +LongitudeToXScroll: + lda eastwest + beq LongitudeToXScrollEast + lda #$00 + sta nametable + lda #179 + sec + sbc tmp + jmp LongitudeToXScrollContinue +LongitudeToXScrollEast: + lda #$01 + sta nametable + lda tmp +LongitudeToXScrollContinue: + tay + lda (Longitudes), Y + sec + sbc #$80 + sta xscroll + bcs LongitudeToXScrollDone + lda nametable + eor #%00000001 + sta nametable +LongitudeToXScrollDone: + rts diff --git a/src/decompress.asm b/src/decompress.asm new file mode 100644 index 0000000..667e9a6 --- /dev/null +++ b/src/decompress.asm @@ -0,0 +1,95 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +DecompressAddr: + lda PPU_STATUS + ldy #$00 + lda (addr), Y + sta PPU_ADDR + sta ppuAddr + jsr IncAddr + lda (addr), Y + sta PPU_ADDR + sta (ppuAddr + 1) + jsr IncAddr +DecompressAddrGetRowByteLoop: + jsr CmpAddrAddrEnd + bne DecompressAddrDone + ; addr not addrEnd + lda (addr), Y + sta tmp + jsr IncAddr + lda tmp + cmp #$01 + beq DecompressAddrGetRowByteLoopIs01 + cmp #$02 + beq DecompressAddr + sta PPU_DATA + jmp DecompressAddrGetRowByteLoop +DecompressAddrGetRowByteLoopIs01: + lda PPU_STATUS + jsr IncPPUAddrOneLineDecompress + lda ppuAddr + sta PPU_ADDR + lda (ppuAddr + 1) + sta PPU_ADDR + jmp DecompressAddrGetRowByteLoop +DecompressAddrDone: + rts + +IncPPUAddrOneLineDecompress: + lda (ppuAddr + 1) + clc + adc #$20 + sta (ppuAddr + 1) + lda ppuAddr + adc #$00 + sta ppuAddr + rts + +CmpAddrAddrEnd: + lda (addr + 1) + cmp (addrEnd + 1) + bcc CmpAddrAddrEndLTUpper + bne CmpAddrAddrEndPositive: + lda addr + cmp addrEnd + bcs CmpAddrAddrEndPositive +CmpAddrAddrEndLTUpper: + lda #$00 + rts +CmpAddrAddrEndPositive: + lda #$01 + rts + +IncAddr: + lda addr + clc + adc #$01 + sta addr + lda (addr + 1) + adc #$00 + sta (addr + 1) + rts diff --git a/src/defs.asm b/src/defs.asm new file mode 100644 index 0000000..79c61a4 --- /dev/null +++ b/src/defs.asm @@ -0,0 +1,50 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +CONTROLLER1 = $4016 +CONTROLLER2 = $4017 + +BUTTON_A = 1 << 7 +BUTTON_B = 1 << 6 +BUTTON_SELECT = 1 << 5 +BUTTON_START = 1 << 4 +BUTTON_UP = 1 << 3 +BUTTON_DOWN = 1 << 2 +BUTTON_LEFT = 1 << 1 +BUTTON_RIGHT = 1 << 0 + +PPU_CTRL = $2000 +PPU_MASK = $2001 +PPU_STATUS = $2002 +PPU_OAM_ADDR = $2003 +PPU_OAM_DATA = $2004 +PPU_SCROLL = $2005 +PPU_ADDR = $2006 +PPU_DATA = $2007 + +OAM_DMA = $4014 +APU_FRAME_COUNTER = $4017 + +CALLBACK = $FFFA diff --git a/src/draw.asm b/src/draw.asm new file mode 100644 index 0000000..8268421 --- /dev/null +++ b/src/draw.asm @@ -0,0 +1,255 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +ResetScroll: + lda #$00 + sta PPU_SCROLL + sta PPU_SCROLL + jsr EnableNMI + rts + +Draw: + lda #%00011110 + sta PPU_MASK + rts + +DisableNMI: + lda #$00 + sta PPU_CTRL + rts + +EnableNMI: + lda #%10000000 + ora patterns + sta PPU_CTRL + rts + +Blank: + lda #%00000110 + sta PPU_MASK + jsr DisableNMI + rts + +ClearPPURAM: + lda #$20 + sta PPU_ADDR + lda #$00 + sta PPU_ADDR + ldy #$10 + ldx #$00 + txa +ClearPPURAMLoop: + sta PPU_DATA + dex + bne ClearPPURAMLoop + ldx #$00 + dey + bne ClearPPURAMLoop + rts + +DrawPreviousFrame: + ldy #$00 +DrawPreviousFrameLoop: + lda PPU_STATUS + lda (drawBuffer), Y + iny + cmp #$8F + beq DrawPreviousFrameDone + cmp #$8E + beq DrawPreviousFrameLoop + sta PPU_ADDR + lda (drawBuffer), Y + iny + sta PPU_ADDR +DrawPreviousFrameLoopContentLoop: + lda (drawBuffer), Y + iny + cmp #$8E + beq DrawPreviousFrameLoop + ; Not #$8E + cmp #$8F + beq DrawPreviousFrameDone + ; Not #$8F + sta PPU_DATA + jmp DrawPreviousFrameLoopContentLoop +DrawPreviousFrameDone: + jsr InitializeDrawBuffer + rts + +InitializeDrawBuffer: + ldy #$00 + sty drawBufferOffset + lda #$8F + sta (drawBuffer), Y + rts + +EndDrawBuffer: + ldy drawBufferOffset + lda #$8F + sta (drawBuffer), Y + iny + sty drawBufferOffset + rts + +SetMapScreenPalettes: + lda PPU_STATUS + lda #$3F + sta PPU_ADDR + lda #$00 + sta PPU_ADDR + lda #<(Palettes) + sta addr + lda #>(Palettes) + sta (addr + 1) + ldy #$00 +SetMapScreenPalettesLoop: + lda (addr), Y + sta PPU_DATA + iny + cpy #$20 + bne SetMapScreenPalettesLoop + rts + +DrawMapScreen: + lda PPU_STATUS + lda #$20 + sta PPU_ADDR + lda #$00 + sta PPU_ADDR + lda #<(West) + sta addr + lda #>(West) + sta (addr + 1) + ldy #$00 + ldx #$04 +DrawMapScreenWest: + lda (addr), Y + sta PPU_DATA + iny + bne DrawMapScreenWest + inc (addr + 1) + dex + bne DrawMapScreenWest + lda PPU_STATUS + lda #$24 + sta PPU_ADDR + lda #$00 + sta PPU_ADDR + lda #<(East) + sta addr + lda #>(East) + sta (addr + 1) + ldx #$04 +DrawMapScreenEast: + lda (addr), Y + sta PPU_DATA + iny + bne DrawMapScreenEast + inc (addr + 1) + dex + bne DrawMapScreenEast + rts + +TopBarText: + .byte $20, $42 + .byte $EE, $EB, $FB, $EF, $E0, $01 + .byte $FB, $F2, $F5, $EF, $E0, $04, $04, $04, $E0, $04, $04, $E0, $04, $04, $04, $FC, $FB, $ED, $01 + .byte $F4, $EB, $FB, $E0, $04, $04, $04, $04, $DF, $01 + .byte $F4, $F7, $F6, $E0, $04, $04, $04, $04, $DF +TopBarTextDone: + +DrawSpriteZero: + lda #$27 + sta $200 + lda #$01 + sta $201 + lda #$01 + sta #$202 + lda #00 + sta $203 + rts + +DrawISSSprites: + lda #$6F + sta $204 + lda #$02 + sta $205 + lda #$00 + sta $206 + lda #$78 + sta $207 + lda #$6F + sta $208 + lda #$03 + sta $209 + lda #$00 + sta $20A + lda #$80 + sta $20B + lda #$6F + sta $20C + lda #$04 + sta $20D + lda #$00 + sta $20E + lda #$88 + sta $20F + lda #$77 + sta $210 + lda #$12 + sta $211 + lda #$00 + sta $212 + lda #$78 + sta $213 + lda #$77 + sta $214 + lda #$13 + sta $215 + lda #$00 + sta $216 + lda #$80 + sta $217 + lda #$77 + sta $218 + lda #$14 + sta $219 + lda #$00 + sta $21A + lda #$88 + sta $21B + rts + +DrawTopBar: + lda #<(TopBarTextDone) + sta addrEnd + lda #>(TopBarTextDone) + sta (addrEnd + 1) + lda #<(TopBarText) + sta addr + lda #>(TopBarText) + sta (addr + 1) + jsr DecompressAddr + rts diff --git a/src/graphics/east.atr b/src/graphics/east.atr new file mode 100644 index 0000000..c9006dc Binary files /dev/null and b/src/graphics/east.atr differ diff --git a/src/graphics/east.nam b/src/graphics/east.nam new file mode 100644 index 0000000..8155645 Binary files /dev/null and b/src/graphics/east.nam differ diff --git a/src/graphics/tilemap.chr b/src/graphics/tilemap.chr new file mode 100644 index 0000000..36aa059 Binary files /dev/null and b/src/graphics/tilemap.chr differ diff --git a/src/graphics/west.atr b/src/graphics/west.atr new file mode 100644 index 0000000..fce1ad3 Binary files /dev/null and b/src/graphics/west.atr differ diff --git a/src/graphics/west.nam b/src/graphics/west.nam new file mode 100644 index 0000000..33646dd Binary files /dev/null and b/src/graphics/west.nam differ diff --git a/src/include.asm b/src/include.asm new file mode 100644 index 0000000..d192c27 --- /dev/null +++ b/src/include.asm @@ -0,0 +1,67 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +Palettes: + .byte $0F, $11, $2A, $30 + .byte $0F, $11, $30, $30 + .byte $0F, $0F, $0F, $30 + .byte $0F, $0F, $0F, $30 + .byte $0F, $2D, $2C, $30 + .byte $0F, $0F, $0F, $0F + .byte $0F, $0F, $0F, $0F + .byte $0F, $0F, $0F, $0F + +West: + .incbin "graphics/west.nam" + .incbin "graphics/west.atr" +East: + .incbin "graphics/east.nam" + .incbin "graphics/east.atr" + +Months: + .byte $F3, $EB, $F6 + .byte $F0, $EF, $EC + .byte $F5, $EB, $F9 + .byte $EB, $F8, $F9 + .byte $F5, $EB, $FF + .byte $F3, $FC, $F6 + .byte $F3, $FC, $F4 + .byte $EB, $FC, $F1 + .byte $FA, $EF, $F8 + .byte $F7, $ED, $FB + .byte $F6, $F7, $FD + .byte $EE, $EF, $ED + +NorthSouth: + .byte $F6, $FA + +EastWest: + .byte $EF, $FE + +Latitudes: + .byte $28, $29, $2a, $2b, $2c, $2d, $2e, $2f, $30, $32, $33, $34, $35, $36, $37, $38, $39, $3a, $3b, $3c, $3d, $3e, $3f, $40, $41, $43, $44, $45, $46, $47, $48, $49, $4a, $4b, $4c, $4d, $4e, $4f, $50, $51, $52, $53, $55, $56, $57, $58, $59, $5a, $5b, $5c, $5d, $5e, $5f, $60, $61, $62, $63, $64, $66, $67, $68, $69, $6a, $6b, $6c, $6d, $6e, $6f, $70, $71, $72, $73, $74, $75, $76, $78, $79, $7a, $7b, $7c, $7d, $7e, $7f, $80, $81, $82, $83, $84, $85, $86, $87, $89, $8a, $8b, $8c, $8d, $8e, $8f, $90, $91, $92, $93, $94, $95, $96, $97, $98, $9a, $9b, $9c, $9d, $9e, $9f, $a0, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $aa, $ac, $ad, $ae, $af, $b0, $b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8, $b9, $ba, $bb, $bd, $be, $bf, $c0, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $ca, $cb, $cc, $cd, $cf, $d0, $d1, $d2, $d3, $d4, $d5, $d6, $d7, $d8, $d9, $da, $db, $dc, $dd, $de, $e0, $e1, $e2, $e3, $e4, $e5, $e6, $e7 + +Longitudes: + .byte $00, $01, $03, $04, $06, $07, $09, $0a, $0b, $0d, $0e, $10, $11, $12, $14, $15, $17, $18, $1a, $1b, $1c, $1e, $1f, $21, $22, $24, $25, $26, $28, $29, $2b, $2c, $2e, $2f, $30, $32, $33, $35, $36, $37, $39, $3a, $3c, $3d, $3f, $40, $41, $43, $44, $46, $47, $49, $4a, $4b, $4d, $4e, $50, $51, $52, $54, $55, $57, $58, $5a, $5b, $5c, $5e, $5f, $61, $62, $64, $65, $66, $68, $69, $6b, $6c, $6e, $6f, $70, $72, $73, $75, $76, $77, $79, $7a, $7c, $7d, $7f, $80, $81, $83, $84, $86, $87, $89, $8a, $8b, $8d, $8e, $90, $91, $92, $94, $95, $97, $98, $9a, $9b, $9c, $9e, $9f, $a1, $a2, $a4, $a5, $a6, $a8, $a9, $ab, $ac, $ae, $af, $b0, $b2, $b3, $b5, $b6, $b7, $b9, $ba, $bc, $bd, $bf, $c0, $c1, $c3, $c4, $c6, $c7, $c9, $ca, $cb, $cd, $ce, $d0, $d1, $d2, $d4, $d5, $d7, $d8, $da, $db, $dc, $de, $df, $e1, $e2, $e4, $e5, $e6, $e8, $e9, $eb, $ec, $ee, $ef, $f0, $f2, $f3, $f5, $f6, $f7, $f9, $fa, $fc, $fd, $ff, $ff diff --git a/src/iss-nes.asm b/src/iss-nes.asm new file mode 100644 index 0000000..3fd437f --- /dev/null +++ b/src/iss-nes.asm @@ -0,0 +1,46 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + + .db "NES", $1A + .db $02 + .db $01 + .db $01 + .db $00 + .db 0, 0, 0, 0, 0, 0, 0, 0 + +.include "ram.asm" +.include "defs.asm" + +.base $8000 + +.include "prg.asm" + + .pad CALLBACK, #$FF + .dw NMI + .dw RESET + .dw 0 + +.base $0000 + .incbin "graphics/tilemap.chr" diff --git a/src/prg.asm b/src/prg.asm new file mode 100644 index 0000000..6e433a9 --- /dev/null +++ b/src/prg.asm @@ -0,0 +1,141 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +RESET: + sei + cld + ldx #$40 + stx APU_FRAME_COUNTER + ldx #$FF + txs + inx + lda #%00000110 + sta PPU_MASK + lda #$00 + sta PPU_CTRL + stx $4010 + ldy #$00 + +InitialVWait: + lda PPU_STATUS + bpl InitialVWait +InitialVWait2: + lda PPU_STATUS + bpl InitialVWait2 + +InitializeRAM: + ldx #$00 +InitializeRAMLoop: + lda #$00 + sta $0000, x + sta $0100, x + sta $0300, x + sta $0400, x + sta $0500, x + sta $0600, x + sta $0700, x + lda #$FE + sta $0200, x + inx + bne InitializeRAMLoop + lda #%00001000 + sta patterns + jsr ClearPPURAM + jsr SetMapScreenPalettes + jsr DrawMapScreen + jsr DrawSpriteZero + jsr DrawISSSprites + jsr DrawTopBar + jsr InitializeDrawBuffer + jsr SetDefaultDate + jsr ResetScroll + +Forever: + jmp Forever + +NMI: + lda #$00 + sta PPU_OAM_ADDR + lda #$02 + sta OAM_DMA + lda PPU_STATUS + jsr Draw + jsr DrawPreviousFrame + jsr ResetScroll +Sprite0ClearWait: + bit PPU_STATUS + bvs Sprite0ClearWait +Sprite0HitWait: + bit PPU_STATUS + bvc Sprite0HitWait + lda #%10000000 + ora nametable + ora patterns + sta PPU_CTRL + lda xscroll + sta PPU_SCROLL + +NMIDone: + jsr Update + rti + +Update: + lda lua + beq UpdateNotLua + jsr PollControllerFinished + jmp UpdateLuaContinue +UpdateNotLua: + jsr PollControllerSync +UpdateLuaContinue: + ldy drawBufferOffset + lda #$8F + sta (drawBuffer), Y + iny + sta drawBufferOffset + rts + +SetPalette: + lda #<(Palettes) + sta addr + lda #>(Palettes) + sta (addr + 1) + lda PPU_STATUS + lda #$3F + sta PPU_ADDR + lda #$00 + sta PPU_ADDR + ldy #$00 +SetPaletteLoop: + lda (addr), Y + sta PPU_DATA + iny + cpy #$20 + bne SetPaletteLoop + rts + +.include "decompress.asm" +.include "draw.asm" +.include "include.asm" +.include "controller.asm" diff --git a/src/ram.asm b/src/ram.asm new file mode 100644 index 0000000..e4ae1d1 --- /dev/null +++ b/src/ram.asm @@ -0,0 +1,68 @@ +; Copyright (C) 2020, Vi Grey +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; 1. Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; 2. Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; +; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +; SUCH DAMAGE. + +.enum $0000 +Variables: + lua dsb 1 + fps dsb 1 + region dsb 1 + regionTmp dsb 1 + screen dsb 1 + addr dsb 2 + addrEnd dsb 2 + ppuAddr dsb 2 + xscroll dsb 1 + nametable dsb 1 + patterns dsb 1 + tmp dsb 1 +.ende + +.enum $0300 +DrawBufferVariables: + drawBufferOffset dsb 1 + drawBufferOffsetTmp dsb 1 + drawBuffer dsb 200 + draw dsb 1 +.ende + +.enum $0400 +TopBarVariables: + month dsb 1 + day dsb 2 + year dsb 4 + hour dsb 2 + minute dsb 2 + second dsb 2 + lat dsb 4 + lon dsb 5 + northsouth dsb 1 + eastwest dsb 1 +.ende + +.enum $0500 + controller1 dsb 10 + controllersync dsb 1 + controllervalid dsb 1 +.ende