ram.asm - RLH-2110/gbCalc GitHub Wiki

Table of Contents

Overview
High Memory
Control Variables
Normal
Temporary
Multiplication routine in RAM

Overview

This file contains all the defined ram variables so we can easily keep track of them.

High Memory

In the High Memory We have some scratch variables and the stack.

SECTION "highScratch",HRAM[$FF80]
wCounter::	 dw ; counter that can be used
wTmpNumber:: dw ; saves a number
wTmpByte:: db ; saves a byte

SECTION "stack",HRAM[$FFE0]
ds $1E ; reserve $FFE0 to $FFFE as stack memory (30 bytes (15 pushes))

The scratch variables are mostly used in calc.asm in the division routine, but they could be used anywhere in the future.
The stack is 30 bytes big meaning we can do 15 pushes at most

Control Variables

these variables are used by the main routine to see what to do.

section "control", WRAM0
wFinishedWork:: db ; z = finished work, nz = did not finish work
wPrintResult:: db ; z = do not print, nz = print

wFinishedWork = did we finish the work and can enter the main routine?
wPrintResult = should we call the print routine?

Normal

these variables save the inputs

SECTION "Input Variables", WRAM0
wCurKeys:: db
wNewKeys:: db

wCurKeys = currently pressed keys wNewKeys = new keys that were pressed

These save the state of the cursor

section "cursorVariables", WRAM0
wCursorState:: db ; what section is the cursor in
wCursorPos:: db ; offset for the cursor used in numbers

Numbers and flags

section "numbers", WRAM0
wNumber0:: dw
wNumber1:: dw
wResult:: dw
wResultError:: db ; 0 = false FF = true
wResultNegative:: db ; z = positive, nz = negative
wNumber0Negative:: db ; z = positive, nz = negative
wNumber1Negative:: db ; z = positive, nz = negative

wStoredNumber0:: dw ; nuber stored by the user (init 0)
wStoredNumber1:: dw ; (unused in this version) number stored by the user (init 0)

wStoredNumber0, wStoredNumber1 = numbers used for storeing and retieving numbers by the user. see store.asm
wResultError boolean for if we got an error while calculating the other "booleans" are not booleans, but the extracted signs. so 0 = positive 1 = negative

Temporary

These are mostly used for the double dablle code, but they could be used somewhere else, but usage of high memory is prefered.

SECTION "temp Variables", WRAM0
wDoubleDabble:: ; uses 5 bytes (wTmp1,wTmp2,wTmpH)
wTmp1:: dw
wTmp2:: dw
wTmpH:: db
wTmpL:: db

Multiplication routine in RAM

I decided to use SMC in the Multiplication routine for fun, but code is in ROM and can not be altered, so part of the multiplication routine is copied into ram.

section "MUL code RAM", WRAM0[$CF00]
Math_mul_loop_ram:: ds $FF ; reserve the rest of the memory for the multiplication loop

The code is copied into RAM during initialsation in main.asm