Skip to content

Commit

Permalink
Update of tooling; fixing code style; new macro mulAndAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmaleckicg authored and maciejmalecki committed Nov 15, 2021
1 parent 446615e commit aa329b0
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
# IDE and tool files
.idea
.ra
.vscode
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# c64lib/common
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CircleCI](https://circleci.com/gh/c64lib/common/tree/master.svg?style=svg)](https://circleci.com/gh/c64lib/common/tree/master)
[![CircleCI](https://circleci.com/gh/c64lib/common/tree/develop.svg?style=svg)](https://circleci.com/gh/c64lib/common/tree/develop)
[![CircleCI](https://circleci.com/gh/c64lib/common/tree/master.svg?style=shield)](https://circleci.com/gh/c64lib/common/tree/master)
[![CircleCI](https://circleci.com/gh/c64lib/common/tree/develop.svg?style=shield)](https://circleci.com/gh/c64lib/common/tree/develop)
[![Gitter](https://badges.gitter.im/c64lib/community.svg)](https://gitter.im/c64lib/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

Check our [User's Manual](https://c64lib.github.io/user-manual/#_common) for more documentation on this library.

## Change log

### Changes in version 0.3.0

* New macro: `math.asm/mulAndAdd` - multiple two numbers and add result to memory location.

### Changes in version 0.2.0

* Public elements of library are also declared as global symbols in "-global.asm" files using `c64lib_` name prefix.
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
plugins {
id "com.github.c64lib.retro-assembler" version "1.1.0-rc01"
id "com.github.c64lib.retro-assembler" version "1.4.5"
}

repositories {
jcenter()
mavenCentral()
}

apply plugin: "com.github.c64lib.retro-assembler"

retroProject {

dialect = "KickAssembler"
dialectVersion = "5.13"
dialectVersion = "5.22"
libDirs = ["..", ".ra/deps/c64lib"]

libFromGitHub "c64lib/64spec", "0.7.0pr"
Expand Down
2 changes: 1 addition & 1 deletion lib/common.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
* Why Kickassembler does not support bitwise negation on numerical values?
*
*
* Params:
* value: byte to be negated
*/
Expand Down
28 changes: 14 additions & 14 deletions lib/invoke.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
.filenamespace c64lib

/*
* Preserves return address that is used with JSR.
* Preserves return address that is used with JSR.
* Should be called at beginning of subroutine.
*
* Params:
* placeholderPtr - pointer to the memory location (that is local variable of the subroutine)
*
* Params:
* placeholderPtr - pointer to the memory location (that is local variable of the subroutine)
* where return address will be preserved.
*/
.macro invokeStackBegin(placeholderPtr) {
Expand All @@ -33,9 +33,9 @@
/*
* Restores return address that will be then used with RTS.
* Should be called at the very end of subroutine just before RTS.
*
* Params:
* placeholderPtr - pointer to the memory location (that is local variable of the subroutine)
*
* Params:
* placeholderPtr - pointer to the memory location (that is local variable of the subroutine)
* from where return address will be restored.
*/
.macro invokeStackEnd(placeholderPtr) {
Expand All @@ -46,7 +46,7 @@
}

/*
* Pushes byte value as a parameter to the subroutine.
* Pushes byte value as a parameter to the subroutine.
* Such value should be then pulled in subroutine in opposite order.
*
* Params:
Expand All @@ -58,7 +58,7 @@
}

/*
* Pushes two bytes value as a parameter to the subroutine.
* Pushes two bytes value as a parameter to the subroutine.
* Such value should be then pulled in subroutine in opposite order.
*
* Params:
Expand All @@ -70,7 +70,7 @@
}

/*
* Pushes byte pointed by an address as a parameter to the subroutine.
* Pushes byte pointed by an address as a parameter to the subroutine.
* Such value should be then pulled in subroutine in opposite order.
*
* Params:
Expand All @@ -82,7 +82,7 @@
}

/*
* Pushes two bytes value pointed by an address as a parameter to the subroutine.
* Pushes two bytes value pointed by an address as a parameter to the subroutine.
* Such value should be then pulled in subroutine in opposite order.
*
* Params:
Expand All @@ -94,7 +94,7 @@
}

/*
* Pulls byte value from the stack and stores it under given address.
* Pulls byte value from the stack and stores it under given address.
*
* Params:
* placeholderPtr - pointer to the memory location where given byte will be pulled to
Expand All @@ -105,7 +105,7 @@
}

/*
* Pulls two bytes value from the stack and stores it under given address.
* Pulls two bytes value from the stack and stores it under given address.
*
* Params:
* placeholderPtr - pointer to the beginning of memory location where given two bytes will be pulled to
Expand All @@ -128,5 +128,5 @@
pla
.for (var i = 0; i < placeholderPtrList.size(); i++) sta placeholderPtrList.get(i)
}
.assert "pullParamWList([$aaaa, $bbbb])", {pullParamWList(List().add($aaaa, $bbbb))},
.assert "pullParamWList([$aaaa, $bbbb])", {pullParamWList(List().add($aaaa, $bbbb))},
{pla;sta $aaaa + 1; sta $bbbb + 1; pla; sta $aaaa; sta $bbbb}
1 change: 1 addition & 0 deletions lib/math-global.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.macro @c64lib_asl16(low) { asl16(low) }
.macro @c64lib_inc16(destination) { inc16(destination) }
.macro @c64lib_dec16(destination) { dec16(destination) }
.macro @c64lib_mulAndAdd(left, right, targetAddr) { mulAndAdd(left, right, targetAddr) }
32 changes: 25 additions & 7 deletions lib/math.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
clc; lda $A000; adc #$02; sta $A000
lda $A001; adc #$01; sta $A001
}

/*
* Subtracts 16 bit number "value" from given memory cell specified by "low" address.
*
Expand All @@ -43,7 +43,7 @@
sec; lda $A000; sbc #0; sta $A000
lda $A001; sbc #1; sta $A001
}

/*
* Adds value from "source" memory location to value in "destination" memory location.
*
Expand Down Expand Up @@ -71,13 +71,13 @@
adc incArgument(destination)
sta incArgument(destination)
}

/*
* Subtracts value from "source" memory location from value in "destination" memory location.
*
* MOD: A, C
*/
.macro subMem16(source, destination) {
.macro subMem16(source, destination) {
sub16 source : destination
}
.assert "subMem16($A000, $B000)", { subMem16($A000, $B000) }, {
Expand All @@ -99,10 +99,10 @@
sbc incArgument(source)
sta incArgument(destination)
}

/*
* Shifts left 2 byte number specified with "low" address. Carry flag indicates last bit that has been "shifted out".
*
*
* MOD: A, C
*/
.macro asl16(low) {
Expand All @@ -111,7 +111,7 @@

/*
* Shifts left 2 byte number specified with "low" address. Carry flag indicates last bit that has been "shifted out".
*
*
* MOD: A, C
*/
.pseudocommand asl16 low {
Expand Down Expand Up @@ -168,3 +168,21 @@
dec incArgument(destination)
!:
}

/*
* Multiplies left times right. Target value will be added to the value stored in targetAddr.
* Mod: A, X
*/
.macro mulAndAdd(left, right, targetAddr) {
ldx #right
!:
clc
lda #left
adc targetAddr
sta targetAddr
lda #0
adc targetAddr + 1
sta targetAddr + 1
dex
bne !-
}
4 changes: 2 additions & 2 deletions lib/mem.asm
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ end:
.macro rotateMemRightFast(startPtr, count) {
lda startPtr
pha

.for(var i = 0; i < count - 1; i++) {
lda startPtr + i + 1
sta startPtr + i
}

pla
sta startPtr + count - 1
}
Expand Down
4 changes: 2 additions & 2 deletions lib/sub/copy-large-mem-forward.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
pullParamW(copyCounter)
pullParamW(staNext)
pullParamW(ldaNext)

addMem16(copyCounter, staNext)
addMem16(copyCounter, ldaNext)
copyNextPage:
Expand All @@ -37,7 +37,7 @@
bne copyNext
jmp copyNextPage
end:

invokeStackEnd(returnPtr)
rts
// local vars
Expand Down
4 changes: 2 additions & 2 deletions lib/sub/fill-mem.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
sta value + 1 // preserve A for later usage
invokeStackBegin(returnPtr)
pullParamW(address + 1)

value: lda #$00
loop:
dex
address: sta $ffff, x
bne loop

invokeStackEnd(returnPtr)
rts
// local vars
Expand Down
6 changes: 3 additions & 3 deletions lib/sub/fill-screen.asm
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*/
.namespace c64lib {
fillScreen: {

sta value + 1
invokeStackBegin(returnPtr)
pullParamWList(List().add(sta0 + 1, sta1 + 1, sta2 + 1, sta3 + 1))
add16($0100, sta1 + 1)
add16($0200, sta2 + 1)
add16($0300, sta3 + 1)

value: lda #$00
ldx #$00
loop:
Expand All @@ -29,7 +29,7 @@
sta3: sta $ffff, x
inx
bne loop

invokeStackEnd(returnPtr)
rts
// local vars
Expand Down
6 changes: 3 additions & 3 deletions lib/sub/rotate-mem-right.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* Stack WORD - address
* OUT:
* none
* MOD:
* MOD:
* A, X
*/
.namespace c64lib {
.namespace c64lib {
rotateMemRight: {

invokeStackBegin(returnPtr)
Expand All @@ -27,7 +27,7 @@
bne loop
lda preserve
sta staLast:$ffff

invokeStackEnd(returnPtr)
rts
// local vars
Expand Down
6 changes: 3 additions & 3 deletions spec/math-add16.spec.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sfspec: init_spec()
assert_c_cleared
assert_equal16 result : expected
}

it("1 + 0 = 1"); {
c64lib_set16(1, operand)
c64lib_set16(0, result)
Expand All @@ -39,7 +39,7 @@ sfspec: init_spec()
assert_c_cleared
assert_equal16 result : expected
}

it("256 + 0 = 256"); {
c64lib_set16(256, operand)
c64lib_set16(0, result)
Expand All @@ -48,7 +48,7 @@ sfspec: init_spec()
assert_c_cleared
assert_equal16 result : expected
}

it("0 + 256 = 256"); {
c64lib_set16(0, operand)
c64lib_set16(256, result)
Expand Down
4 changes: 2 additions & 2 deletions spec/math-dec16.spec.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ sfspec: init_spec()
c64lib_dec16(dec16Actual)
assert_equal16 dec16Actual: dec16Expected
}

it("of 256 gives 255"); {
c64lib_dec16(dec16WordActual)
assert_equal16 dec16WordActual: dec16WordActual
}

finish_spec()

* = * "Data"
Expand Down
6 changes: 3 additions & 3 deletions spec/mem-cmp16.spec.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ sfspec: init_spec()
c64lib_cmp16(256, _256)
assert_z_set
}

it("of 0 and 256 gives false"); {
c64lib_cmp16(0, _256)
assert_z_cleared
}

it("of 7 and 7 gives true"); {
c64lib_cmp16(7, _7)
assert_z_set
}

it("of 0 and 0 gives true"); {
c64lib_cmp16(0, _0)
assert_z_set
Expand Down
Loading

0 comments on commit aa329b0

Please sign in to comment.