From aa4191aec26d4c20a8e41865ac1a3e4527ed40c7 Mon Sep 17 00:00:00 2001 From: jeffman Date: Thu, 6 Dec 2018 23:05:00 -0500 Subject: [PATCH] bin_to_bcd can be called from C Remove old cash window formatting code (we'll be rewriting it in C) --- compiled/ext.c | 1 + compiled/vwf.h | 1 + m2-formatting.asm | 80 +++-------------------------------------------- 3 files changed, 6 insertions(+), 76 deletions(-) diff --git a/compiled/ext.c b/compiled/ext.c index 8d206b3..99b091b 100644 --- a/compiled/ext.c +++ b/compiled/ext.c @@ -2,3 +2,4 @@ typedef unsigned char byte; void __attribute__((naked)) cpufastset(void *source, void *dest, int mode) {} byte* __attribute__((naked)) m2_strlookup(int *offset_table, byte *strings, int index) {} +int __attribute__((naked)) bin_to_bcd(int value, int* digit_count) {} diff --git a/compiled/vwf.h b/compiled/vwf.h index 26bf625..dcb14e8 100644 --- a/compiled/vwf.h +++ b/compiled/vwf.h @@ -76,3 +76,4 @@ extern byte m12_other_str8[]; extern void cpufastset(void *source, void *dest, int mode); extern byte* m2_strlookup(int *offset_table, byte *strings, int index); +extern int bin_to_bcd(int value, int* digit_count); diff --git a/m2-formatting.asm b/m2-formatting.asm index 9c7461c..609dcac 100644 --- a/m2-formatting.asm +++ b/m2-formatting.asm @@ -3,14 +3,14 @@ // int bin_to_bcd(int binary) // In: // r0: binary number +// r1: out pointer; amount of digits used will be returned here // Out: // r0: BCD-coded number -// r1: amount of digits used //============================================================================== bin_to_bcd: -push {r2-r7,lr} +push {r1-r7,lr} mov r2,r8 mov r3,r9 push {r2-r3} @@ -120,6 +120,8 @@ mov r1,r3 pop {r2-r3} mov r8,r2 mov r9,r3 +pop {r2} +str r1,[r2] pop {r2-r7,pc} @@ -196,77 +198,3 @@ add r1,r1,r4 //-------------------------------- mov r0,r1 pop {r1-r4,pc} - - -//============================================================================== -// ushort format_cash(int amount, char* output, int digits) -// In: -// r0: amount -// r1: output string -// r2: digits -// Out: -// r0: = digits - (digits rendered) - 1 -//============================================================================== - -format_cash: - -push {r1-r7,lr} -mov r4,r1 -mov r6,r2 - -//-------------------------------- -// Figure out how many digits we need -bl bin_to_bcd -mov r5,r1 -mov r7,r1 - -// The window is 56 pixels wide: -// each digit uses 6 pixels, the 0x sign uses 6, and the -// double-zero uses 8 -mov r2,42 // = 56 - 6 - 8 -lsl r3,r1,2 -add r3,r3,r1 -add r1,r1,r3 // r1 *= 6 -sub r1,r2,r1 // r1 = 42 - r1 - -// Store the control code to the output -mov r2,0x5F -strb r2,[r4,0] -mov r2,0xFF -strb r2,[r4,1] -strb r1,[r4,2] - -// Store the dollar sign -mov r2,0x54 -strb r2,[r4,3] -add r4,r4,4 - -// Store the digits to the output -mov r2,8 -sub r2,r2,r5 -lsl r2,r2,2 -lsl r0,r2 // Now the number is pushed to the left of the register - -@@prev: -lsr r1,r0,28 // Get the left-most digit -add r1,0x60 // Integer-to-char -strb r1,[r4,0] -add r4,r4,1 -lsl r0,r0,4 -sub r5,r5,1 -bne @@prev - -// Store the double-zero sign -mov r1,0x56 -strb r1,[r4,0] - -// Store the end code -mov r1,0 -strb r1,[r4,1] -mov r1,0xFF -strb r1,[r4,2] - -//-------------------------------- -sub r5,r6,r7 -sub r0,r5,1 -pop {r1-r7,pc}