Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
pubby committed Nov 23, 2022
1 parent 4779bd1 commit 290a3ad
Show file tree
Hide file tree
Showing 34 changed files with 3,509 additions and 3,019 deletions.
23 changes: 23 additions & 0 deletions lib/LICENSE_1_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
65 changes: 65 additions & 0 deletions lib/oam.fab
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2022, Patrick Bene
* This file is distributed under the Boost Software License, Version 1.0.
* See LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt
*/

// Code for manipulating OAM (Object Attribute Memory),
// which is the memory that represents sprites.
// See: https://www.nesdev.org/wiki/PPU_OAM

vars /oam
// This array represents the CPU-side copy of OAM.
// Make your modifications to it, then call 'ppu_upload_oam' during VBLANK.
U[256] oam
: +align

// Offsets into OAM, as determined by the hardware:
ct Int OAM_Y = 0
ct Int OAM_P = 1
ct Int OAM_A = 2
ct Int OAM_X = 3

// Copies 'oam' into PPU memory. Call during VBLANK only.
fn ppu_upload_oam(U offset)
: employs /oam
: +inline
fence
{OAMADDR}(offset)
{OAMDMA}((&oam).b)

// !!! For the following functions: !!!
// 'index' must be a multiple of 4, otherwise the behavior is undefined.

// Hides every sprite, starting from 'index':
fn hide_oam(U index)
: +inline
do for(; index; index += 4)
oam{OAM_Y + index} = $FF

// The 'set_oam' functions use the '{}' operator for array indexing
// instead of '[]', as it's more efficient in this case.

fn set_oam_x(U index, U x)
: +inline
oam{OAM_X + index} = x

fn set_oam_y(U index, U y)
: +inline
oam{OAM_Y + index} = y

fn set_oam_p(U index, U p)
: +inline
oam{OAM_P + index} = p

fn set_oam_a(U index, U a)
: +inline
oam{OAM_A + index} = a

fn set_oam(U index, U x, U y, U p, U a)
: +inline
oam{OAM_Y + index} = y
oam{OAM_P + index} = p
oam{OAM_A + index} = a
oam{OAM_X + index} = x

16 changes: 13 additions & 3 deletions lib/pad.fab
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright (c) 2022, Patrick Bene
* This file is distributed under the Boost Software License, Version 1.0.
* See LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt
*/

// Code for reading and handling gamepad button presses.
// See: https://www.nesdev.org/wiki/Standard_controller

// Gamepad button flags:
ct U BUTTON_A = %10000000
ct U BUTTON_B = %01000000
Expand All @@ -9,19 +18,20 @@ ct U BUTTON_LEFT = %00000010
ct U BUTTON_RIGHT = %00000001
ct U BUTTON_DPAD = BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | BUTTON_RIGHT

// This struct provides an interface to a single gamepad.
// To use, AND the fields with the button flags above.
struct Pad
U held
U pressed
U released

vars /pad
// [0] for the first controller, [1] for the second
Pad[2] pads
Pad[2] pads = Pad[2]()

// Reads the current gamepad state into 'pads'.
asm fn read_pads()
: vars /pad
: data
: employs /pad
default
ldx &pads.held+0
ldy #1
Expand Down
11 changes: 11 additions & 0 deletions lib/palette.fab
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2022, Patrick Bene
* This file is distributed under the Boost Software License, Version 1.0.
* See LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt
*/

// Code for working with palettes,
// i.e. the limited set of colors the NES can display at once.
// See: https://www.nesdev.org/wiki/PPU_palettes

// Copies the global variable 'palette' into the PPU's internal palette memory.
fn ppu_upload_palette()
{PPUSTATUS}()
Expand Down Expand Up @@ -76,3 +86,4 @@ ct U[25] example_palette = U[25](
$08, $1A, $2C,

$0F)

6 changes: 4 additions & 2 deletions lib/pbz.fab
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// TODO

data /pbz

asm fn load_pbz(CC/pbz ptr, U tiles)
: vars
: data /pbz
: employs /pbz
vars
U run_mask
label write_plane
Expand Down
28 changes: 24 additions & 4 deletions lib/rng.fab
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/*
* Copyright (c) 2022, Patrick Bene
* This file is distributed under the Boost Software License, Version 1.0.
* See LICENSE_1_0.txt or https://www.boost.org/LICENSE_1_0.txt
*/

// RNG means random number generator.
// This file contains code for generating random numbers.

vars /rng
U[2] rng_state = U[2](1, 1)

// Helper function for setting 'rng_state'.
fn seed(UU nonzero)
: +inline
rng_state[0] = nonzero.a
rng_state[1] = nonzero.b

// Returns a pseudo-random 8-bit value.
asm fn rand() U
: vars /rng
: data
: employs /rng
default
lda &rng_state+0
asl
Expand All @@ -23,9 +35,17 @@ asm fn rand() U
sta &return
rts

// Returns a pseudo-random 16-bit value.
fn rand16() UU
: +inline
UU result
result.a = rand()
result.b = rand()
return result

// Returns a bitmask that can hold any value less than or equal to argument 'num'.
asm fn ceil_mask(U num) U
: vars
: data
: employs
default
ldx #$FF
lda &num
Expand Down
5 changes: 2 additions & 3 deletions lib/string.fab
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

// TODO

vars /decompress_string_vars
CC/strings decompress_string_ptr
Expand All @@ -15,8 +15,7 @@ charmap foo("\0\n", "abcdefghijklmnopqrstuvwxyz
// Decompresses a single character of the string, returning it.
//
asm fn decompress_string() U
: vars /decompress_string_vars
: data /strings
: employs /strings /decompress_string_vars
vars
U stack

Expand Down
Loading

0 comments on commit 290a3ad

Please sign in to comment.