c128lib Base
Base macros for C128
Loading...
Searching...
No Matches
math-global.asm File Reference

Math module. More...

Functions

macro c128lib_Add16 (value, dest)
 This macro performs a 16-bit addition operation.
 
macro c128lib_Sub16 (value, dest)
 This macro performs a 16-bit subtraction operation.
 
macro c128lib_Asl16 (address)
 This macro performs a 16-bit arithmetic shift left (ASL) operation.
 
macro c128lib_Inc16 (address)
 This macro performs a 16-bit increment operation.
 
macro c128lib_Dec16 (address)
 This macro performs a 16-bit decrement operation.
 
macro c128lib_Div16By16 (dividend, divisor, remainder)
 Divides a 16 bit number by a 16 bit number.
 
macro c128lib_Div16By8 (dividend, divisor, remainder)
 Divides a 16 bit number by a 8 bit number.
 

Detailed Description

Math module.

Simple macros for math operations.

Author
Raffaele Intorcia raffa.nosp@m.ele..nosp@m.intor.nosp@m.cia@.nosp@m.gmail.nosp@m..com
John Palermo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Date
2024

Function Documentation

◆ c128lib_Add16()

macro c128lib_Add16 ( value ,
dest  )

This macro performs a 16-bit addition operation.

The macro uses the 6502 processor's ADC (Add with Carry) instruction to perform the addition. It first clears the carry flag with CLC, then adds the low byte of the value to the low byte at the destination, and stores the result back in the low byte at the destination. It then adds the high byte of the value to the high byte at the destination, taking into account any carry from the low byte addition, and stores the result back in the high byte at the destination.

Parameters
[in]valueThe 16-bit value to add.
[in,out]destThe memory location of the other 16-bit value.
Returns
Result is returned in dest memory location.
Since
1.0.0

◆ c128lib_Sub16()

macro c128lib_Sub16 ( value ,
dest  )

This macro performs a 16-bit subtraction operation.

The macro uses the 6502 processor's SBC (Subtract with Carry) instruction to perform the subtraction. It first sets the carry flag with SEC, then subtracts the low byte of the value from the low byte at the destination, and stores the result back in the low byte at the destination. It then subtracts the high byte of the value from the high byte at the destination, taking into account any borrow from the low byte subtraction, and stores the result back in the high byte at the destination.

Parameters
[in]valueThe 16-bit value to subtract.
[in,out]destThe memory location of the other 16-bit value.
Returns
Result is returned in dest memory location.
Remarks
Register .A will be modified.
Flags N, O, Z and C will be affected.
Since
1.0.0

◆ c128lib_Asl16()

macro c128lib_Asl16 ( address )

This macro performs a 16-bit arithmetic shift left (ASL) operation.

The macro uses the 6502 processor's ASL (Arithmetic Shift Left) instruction to perform the shift. It first shifts the low byte at the value location left, then shifts the high byte at the value location left, taking into account any carry from the low byte shift.

Parameters
[in,out]addressThe memory location of the 16-bit value to shift left.
Returns
Result is returned in address memory location.
Remarks
Register .A will be modified.
Flags N, Z and C will be affected.
Since
1.0.0

◆ c128lib_Inc16()

macro c128lib_Inc16 ( address )

This macro performs a 16-bit increment operation.

The macro uses the 6502 processor's INC (INCrement memory) instruction to perform the decrement. It first increments the low byte at the destination. If this results is zero, it then increments the high byte at the destination.

Parameters
[in,out]addressThe memory location of the 16-bit value to increment.
Returns
Result is returned in address memory location.
Remarks
Flags N and Z will be affected.
Since
1.0.0

◆ c128lib_Dec16()

macro c128lib_Dec16 ( address )

This macro performs a 16-bit decrement operation.

The macro uses the 6502 processor's DEC (DECrement memory) instruction to perform the decrement. It first decrements the low byte at the destination. If this results in a borrow (i.e., the low byte was 0 and becomes 0xFF), it then decrements the high byte at the destination.

Parameters
[in,out]addressThe memory location of the 16-bit value to decrement.
Returns
Result is returned in address memory location.
Remarks
Register .A will be modified.
Flags N and Z will be affected.
Since
1.0.0

◆ c128lib_Div16By16()

macro c128lib_Div16By16 ( dividend ,
divisor ,
remainder  )

Divides a 16 bit number by a 16 bit number.

Divides the two-byte number dividend by the two-byte number divisor, leaving the quotient in dividend and the remainder in remainder. Addressing mode of 16-bit numbers uses little endian.

Parameters
[in,out]dividenddividend and also quotient
[in]divisordivisor
[out]remainderremainder (wide as divisor)
Remarks
Registers .A, .X and .Y will be modified.
Flags N, O, Z and C will be affected.
Since
1.0.0

◆ c128lib_Div16By8()

macro c128lib_Div16By8 ( dividend ,
divisor ,
remainder  )

Divides a 16 bit number by a 8 bit number.

Divides the two-byte number dividend by the one-byte number divisor, leaving the quotient in dividend and the remainder in remainder. Addressing mode of 16-bit numbers uses little endian.

Parameters
[in,out]dividenddividend and also quotient
[in]divisordivisor
[out]remainderremainder (wide as divisor)
Remarks
Registers .A and .X will be modified.
Flags N, O, Z and C will be affected.
Since
1.0.0