Re: Apple Monitor: Print Integer? [message #347628 is a reply to message #347613] |
Thu, 06 July 2017 14:40 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
> Interesting idea! Are you thinking something along these 65C02 lines ... ?
>
> PrintUint16
> STX _temp
> PHA ; Optimized: STA _temp+1
>
> LDX #0
> PHX
> PHX
> PHX
>
> :
>
> TSX
> _DoubleDabble ; Y=FD Y=FE Y=FF Y=00
>
> LDA $FF,X ; ZP,X
> ADC $FF,X
> STA $FF,X
Yes, something like that, but you can't use the "ZP,X" access because it won't extend into the stack page, so it might not save anything.
|
|
|
Re: Apple Monitor: Print Integer? [message #347630 is a reply to message #347628] |
Thu, 06 July 2017 15:34 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 11:40:57 AM UTC-7, qkumba wrote:
> Yes, something like that, but you can't use the "ZP,X" access because it won't extend into the stack page, so it might not save anything.
Yeah, we lose the ZP,X and are forced to use a 16-bit,X addressing mode. :-/
Plus the over-head of having to manage the stack means we don't win here.
Maybe you can edge out a few more bytes? :-)
0900:A9 12 A2 34 4C 07 09 A0
0908:00 48 DA 5A 5A 5A A0 10
0910:F8 BA 8E 30 09 1E 04 01
0918:3E 05 01 20 3C 09 20 3C
0920:09 20 3C 09 88 D0 EA D8
0928:BD 00 01 20 47 09 CA E0
0930:00 D0 F5 8A 69 04 AA 9A
0938:98 F0 1C 60 BD 01 01 7D
0940:01 01 9D 01 01 E8 60 48
0948:20 7B F8 20 51 09 68 29
0950:0F D0 04 C0 00 F0 E4 C9
0958:0A 90 02 69 06 69 B0 C8
0960:4C ED FD
- - - 8< print_uint16_sp.s - - -
; Michael Pohoreski
; https://github.com/Michaelangel007/apple2_print_uint16
; Optimized from printm
; Thanks to qkumba for optimizations
; Thanks to gid for nudging a zero-page version
; F8 ROM Entry Points
COUT = $FDED
SCRN2 = $F879
; Zero-Page Version - 4 locations used
;_temp = $fc
;bcd = $fd ; NOTE: MUST be at $FD for ZP,X addressing in _DoubleDabble
ORG $900 ; Intentionally different from sans-zero-page version for testing both
LDA #$12
LDX #$34
JMP PrintUint16
; Print unsigned 16-bit integer
; A=High byte
; X=Low byte
; Also see: Applesoft LINPRT @ ED24
; ============================================================ ==========
PrintUint16
LDY #0 ; S=F3
PHA ; S+5 = _temp+1 = $105,X S=F1
PHX ; S+4 = _temp+0 = $104,X S=F2
PHY ; S+3 = _bcd[2] = $103,X S=F0
PHY ; S+2 = _bcd[1] = $102,X S=EF
PHY ; S+1 = _bcd[0] = $101,X S=EE
Dec2BCD
LDY #16 ; 16 bits
SED ; "Double Dabble"
_Dec2BCD ; https://en.wikipedia.org/wiki/Double_dabble
TSX ; X=EE
STX _BCDbegin+1 ; *** SELF-MODIFYING
; ASL _temp+0 ; abcd efgh | ijkl mnop |
; ROL _temp+1 ; C=a bcde fghi | jklm nop0 |
; ; Bit 7654_3210 | 7654_3210 |
ASL $104,X ; _temp+0
ROL $105,X ; _temp+1
; LDX #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
_DoubleDabble ; Y=FD Y=FE Y=FF Y=00
JSR Dabble ; X=EF
JSR Dabble ; X=F0
JSR Dabble ; X=F1
DEY
BNE _Dec2BCD
CLD ; Y=0 = output length
BCD2Chars
LDA $100,X ; X=F1, 1F1 -> bcd[2]
JSR HexA ; print 0, 1, or 2 hex digits
DEX
_BCDbegin
CPX #00 ; *** SELF-MODIFIED X == EE ?
BNE BCD2Chars
; Safe to restore stack now since we are done with vars
TXA
ADC #$04 ; C=1 from CPX #EE
TAX
TXS
TYA ; Handle special case input = $0000 of no output
BEQ _HaveLeadingDigit
_PrintDone
RTS
Dabble
LDA $101,X ; bcd,X
ADC $101,X
STA $101,X
INX
RTS
; Converts A to high ASCII digits, prints as they become available
; @return: A will be bottom nibble in high ASCII
HexA
PHA
JSR SCRN2+2 ; LSR x4 == 0>> 4
JSR _HexNib
PLA
AND #$F
_HexNib
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
CPY #0 ; ... then skip storing it
BEQ _PrintDone
_HaveLeadingDigit
CMP #$A ; n < 10 ?
BCC _Hex2Asc
ADC #6 ; n += 6 $A -> +6 + (C=1) = $11
_Hex2Asc
ADC #'0' + $80 ; inverse=remove #$80
PutChar
INY ; Y = output string length
JMP COUT
|
|
|
Re: Apple Monitor: Print Integer? [message #347631 is a reply to message #347614] |
Thu, 06 July 2017 15:46 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 10:55:23 AM UTC-7, gid...@sasktel.net wrote:
>> How would you like to be credited? With Rob or with gid? I've used gid but let me know if you want that changed.
>>
>> Michael
>
>
> You don't have to mention my name. Just call me that hick boy from Saskatchewan. But if you want, use Gids, which is short for my last name Giddings.
Readme and code updated.
Canadian, eh? :-)
Fellow prairie boy here as well. Asquith FTW :-) Well, last millennium.
|
|
|
Re: Apple Monitor: Print Integer? [message #347641 is a reply to message #347630] |
Thu, 06 July 2017 17:11 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
> Yeah, we lose the ZP,X and are forced to use a 16-bit,X addressing mode. :-/
> Plus the over-head of having to manage the stack means we don't win here.
> Maybe you can edge out a few more bytes? :-)
I'll think about it.
In the meantime, the pha/pla in the non-zp version can be fixed for -2 bytes.
|
|
|
Re: Apple Monitor: Print Integer? [message #347644 is a reply to message #347641] |
Thu, 06 July 2017 17:37 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
and how about this:
_HexNib
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
DEX ; ... then skip storing it
_HaveLeadingDigit
INX ; X = flag to specify non-zero was seen
BEQ _PrintDone
|
|
|
Re: Apple Monitor: Print Integer? [message #347646 is a reply to message #347644] |
Thu, 06 July 2017 18:10 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 2:37:38 PM UTC-7, qkumba wrote:
> and how about this:
>
> _HexNib
> BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
> DEX ; ... then skip storing it
>
> _HaveLeadingDigit
> INX ; X = flag to specify non-zero was seen
> BEQ _PrintDone
Nice trick of removing the Compare == Zero by piggy-backing onto the INX. :-)
Updated all 3 versions on GitHub.
Current stats:
* sans-zero-page 89 bytes
* with-zero-page 77 bytes
* with stack page 91 bytes
|
|
|
Re: Apple Monitor: Print Integer? [message #347648 is a reply to message #347646] |
Thu, 06 July 2017 18:26 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
The pha/pla thing, from this:
STX _temp
PHA ; Optimized: STA _temp+1
....
_Dec2BCD
....
PLA
ROL
PHA
LDY #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
_DoubleDabble ; Y=FD Y=FE Y=FF Y=00
....
DEX
BNE _Dec2BCD
PLA ; keep stack
to this:
STX _temp
....
_Dec2BCD
ROL
LDY #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
PHA
_DoubleDabble ; Y=FD Y=FE Y=FF Y=00
....
PLA ; keep stack
DEX
BNE _Dec2BCD
|
|
|
Re: Apple Monitor: Print Integer? [message #347649 is a reply to message #347641] |
Thu, 06 July 2017 18:29 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 2:11:20 PM UTC-7, qkumba wrote:
> In the meantime, the pha/pla in the non-zp version can be fixed for -2 bytes.
I'm not sure how you are removing the pha/pla ...
but with your last DEX / INX / BNE relocation optimization I'll CALL you and RAISE you -8 bytes!
Down to 81 bytes now for non-zp, 69 bytes for zp, and 83 bytes for stack versions. :-)
|
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347652 is a reply to message #347650] |
Thu, 06 July 2017 19:06 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 3:31:56 PM UTC-7, qkumba wrote:
> zpage version can do this:
>
> LDX #0
> LDY #$FD
> _InitBCD
> STX _bcd-$FD,Y
> INY
> BNE _InitBCD
Am I missing something? Not sure how those 9 bytes are better then these 8?
LDY #0
STY _bcd+0
STY _bcd+1
STY _bcd+2
We need X=-3, and Y=16 for the start of the DoubleDabble loop ...
|
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347655 is a reply to message #347653] |
Thu, 06 July 2017 19:25 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 4:12:08 PM UTC-7, Harry Potter wrote:
> Michael, I tried your code, and it *increased* the size of my code, which uses cc65's divide function to get each digit. :(
You are using it wrong then. You _don't_ need any DIGIT = MOD % BASE that is normally used in itoa().
i.e. For example, this 1-liner in Javascript:
var n = 0x1234, txt = ""; for( var i = 0; i < 5; i++ ) { txt += (n % 10); n /= 10; n = n|0; }; console.log( txt.split("").reverse().join("") );
Or in C
#include <stdio.h>
#include <stdint.h>
char* itoa( uint32_t n, int base )
{
const char set[] = "0123456789ABCDEF";
/* */ int length = 0;
#define MAX_DIGITS 32
static char output[ MAX_DIGITS+1 ]; // base 2 = max 32 binary digits + null
if (base < 2) base = 2;
if (base > 16) base = 16;
do
{
output[ length++ ] = set[ n % base ];
n /= base;
} while( n > 0 );
// String Reverse
output[ length ] = 0;
for( int i = 0; i < length/2; i++ )
{
char temp = output[ i ]; // t <- D
output[ i ] = output[length-i-1]; // D <- S
output[length-i-1] = temp; // t ------> S
}
return output;
}
int main()
{
return printf( "%s\n", itoa( 0x1234, 10 ) );
}
What's the context of the problem you are trying to solve ?
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347658 is a reply to message #347652] |
Thu, 06 July 2017 20:01 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
> Am I missing something? Not sure how those 9 bytes are better then these 8?
>
> LDY #0
> STY _bcd+0
> STY _bcd+1
> STY _bcd+2
>
> We need X=-3, and Y=16 for the start of the DoubleDabble loop ...
Err, because clearly I can't count.
I was using non-zp sizes, where there would be a saving if only there were a sty,x.
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347660 is a reply to message #347658] |
Thu, 06 July 2017 20:15 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 5:02:01 PM UTC-7, qkumba wrote:
>> Am I missing something? Not sure how those 9 bytes are better then these 8?
>>
>> LDY #0
>> STY _bcd+0
>> STY _bcd+1
>> STY _bcd+2
>>
>> We need X=-3, and Y=16 for the start of the DoubleDabble loop ...
>
> Err, because clearly I can't count.
> I was using non-zp sizes, where there would be a saving if only there were a sty,x.
Whew! :-)
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347672 is a reply to message #347666] |
Fri, 07 July 2017 00:58 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 7:56:23 PM UTC-7, Denis Molony wrote:
> I can't wait till you guys get it down to a single byte.
We're trying. =P
Joking aside, Peter has done an outstanding job of optimizing.
I'm very happy with the way it has turned out. I'm probably not going to focus on any more optimizations since I have other projects I need to work on but I'll be keeping an eye on them if any more crop up.
|
|
|
Re: Apple Monitor: Print Integer? [message #347691 is a reply to message #347656] |
Fri, 07 July 2017 08:10 |
Harry Potter
Messages: 1304 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 7:26:07 PM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
> On Thursday, July 6, 2017 at 4:22:22 PM UTC-7, Harry Potter wrote:
>> Uhh...Michael: I was wrong about the last message: I wasn't taking into account the optimizations the people here have made to your code. You said your code is online? Where can I find it? :)
>
> https://github.com/Michaelangel007/apple2_print_uint16
The reason I was doing so poorly is that I *kept* the cc65 divide routine in the code. I did this just in case I need the divide routine for a target program. I removed the reference, and I am getting great results. :)
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347704 is a reply to message #347692] |
Fri, 07 July 2017 10:18 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
Considering there are three versions _which_ one isn't working for you?
Have you tried the built in demo?
Which hardware, if any, are you on?
Which emulator, if any, are you using?
I've uploaded a demo.dsk -- does this work?
I've tested with AppleWin, Jace, and Virtual ][ without any issues.
|
|
|
Re: Apple Monitor: Print Integer? [message #347705 is a reply to message #347704] |
Fri, 07 July 2017 10:34 |
Harry Potter
Messages: 1304 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Friday, July 7, 2017 at 10:18:29 AM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
> Considering there are three versions _which_ one isn't working for you?
> Have you tried the built in demo?
> Which hardware, if any, are you on?
> Which emulator, if any, are you using?
>
I'm using the top version of print_uint16_sans_zp.s.
> I've uploaded a demo.dsk -- does this work?
>
> I've tested with AppleWin, Jace, and Virtual ][ without any issues.
I'm using AppleWin and am compiling the program--the test program is in C--using cc65. The following is my version of your code:
---------------------------------
..include "zeropage.inc"
..import negax
;.import _printu
..export _printi
..import pushax, popax
..import tosudiva0
..import _prints, _printc
..export _printu
COUT = $FDED
;.bss
;_output: .res 6
_temp=tmp1
;_bcd=ptr1
..code
_printi:
cpx #0
bpl _printu
;pha
tay
lda #'-'
;jsr $ffd2
jsr _printc
;pla
tya
jsr negax
_printu:
; Michael Pohoreski
; https://github.com/Michaelangel007/apple2_print_uint16
; Optimized from printm
; Thanks to qkumba for optimizations
; Thanks to Gids for nudging a zero-page version
; F8 ROM Entry Points
PRHEXZ = $FDE5
SCRN2 = $F879
;ORG $800
;LDA #$12
;LDX #$34
;JMP PrintUint16
; Print unsigned 16-bit integer
; A=High byte
; X=Low byte
; Also see: Applesoft LINPRT @ ED24
; ============================================================ ==========
PrintUint16:
STX _temp
LDX #0 ; Optional 65C02 version
STX _bcd+0 ; STZ _bcd+0
STX _bcd+1 ; STZ _bcd+1
STX _bcd+2 ; STZ _bcd+2
Dec2BCD:
LDX #16 ; 16 bits
SED ; "Double Dabble"
_Dec2BCD: ; https://en.wikipedia.org/wiki/Double_dabble
ASL _temp+0 ; abcd efgh | ijkl mnop |
ROL _temp+1 ; C=a bcde fghi | jklm nop0 |
; ; Bit 7654_3210 | 7654_3210 |
ROL
PHA ; Optimized: STA _temp+1
LDY #$FD ; $00-$FD=-3 bcd[0] bcd[1] bcd[2] bcd[3]
_DoubleDabble: ; Y=FD Y=FE Y=FF Y=00
LDA _bcd-$FD,Y
ADC _bcd-$FD,Y
STA _bcd-$FD,Y
INY
BNE _DoubleDabble
PLA
DEX
BNE _Dec2BCD
CLD ; X=0 = output length
DecWidth:
LDY #3 ; maximum 6 digits output
BCD2Chars:
LDA _bcd-1,Y
JSR HexA ; print 0, 1, or 2 hex digits
DEY
BNE BCD2Chars
TXA ; Handle special case input = $0000 of no output
BEQ _HaveLeadingDigit
_PrintDone:
RTS
; Converts A to high ASCII digits, prints as they become available
; @return: A will be bottom nibble in high ASCII
HexA:
PHA
JSR SCRN2+2 ; LSR x4 == 0>> 4
;jsr _printc
JSR _HexNib
PLA
AND #$F
_HexNib:
BNE _HaveLeadingDigit ; If have leading zero and no output yet ...
DEX ; ... then skip storing it
_HaveLeadingDigit:
INX ; X = flag to specify non-zero leading digit was seen
BEQ _PrintDone
JMP PRHEXZ
..bss
_bcd: .res 3 ; 6 chars for printing dec
;_temp: .res 0
..code
;jmp tosudiva0
---------------------------
Am I at fault here?
|
|
|
Re: Apple Monitor: Print Integer? [message #347715 is a reply to message #347705] |
Fri, 07 July 2017 12:11 |
qkumba
Messages: 1584 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
> _Dec2BCD: ; https://en.wikipedia.org/wiki/Double_dabble
> ASL _temp+0 ; abcd efgh | ijkl mnop |
> ROL _temp+1 ; C=a bcde fghi | jklm nop0 |
> ; ; Bit 7654_3210 | 7654_3210 |
> ROL
> PHA ; Optimized: STA _temp+1
This is a combination of a previous version and the current version.
Please fetch the current version from Git and replace what you have.
And please tell us the answer to Michael's question:
> I've uploaded a demo.dsk -- does this work?
|
|
|
Re: Apple Monitor: Print Integer? [message #347716 is a reply to message #347705] |
Fri, 07 July 2017 12:28 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Friday, July 7, 2017 at 7:34:34 AM UTC-7, Harry Potter wrote:
> I'm using AppleWin and am compiling the program--the test program is in C--using cc65.
> Am I at fault here?
Yes, you have an integration bug considering the program works across multiple emulators.
Do you have a binary and/or hexdump of your program so I can debug it?
Also, you don't need to manually include my source. I would simplify your cc65 assembly source to:
..feature labels_without_colons
..include "print_uint16_sans_zp.s"
That way you don't have to keep adding colons to the labels in print_uint16_sans_zp.s.
Of course you will need to comment out the corresponding ORG and TEST code in your local copy of print_uint16_sans_zp.s
|
|
|
Re: Apple Monitor: Print Integer? [message #347745 is a reply to message #347716] |
Fri, 07 July 2017 18:46 |
Harry Potter
Messages: 1304 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Friday, July 7, 2017 at 12:28:55 PM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
> Yes, you have an integration bug considering the program works across multiple emulators.
>
Sorry, but what _exactly_ am I doing wrong?
> Do you have a binary and/or hexdump of your program so I can debug it?
>
I can give you the binary file and/or the full source. It is my Apple2SimpleIO library. My e-mail is rose(dot)joseph12(at)yahoo(dot)com.
E-mail me for a copy. :)
> Also, you don't need to manually include my source. I would simplify your cc65 assembly source to:
>
> .feature labels_without_colons
> .include "print_uint16_sans_zp.s"
>
> That way you don't have to keep adding colons to the labels in print_uint16_sans_zp.s.
>
> Of course you will need to comment out the corresponding ORG and TEST code in your local copy of print_uint16_sans_zp.s
I have it my way because I am developing a *library*; others need to use it, and I need a certain name for the function.
|
|
|
Re: Apple Monitor: Print Integer? [message #347748 is a reply to message #347745] |
Fri, 07 July 2017 20:05 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Friday, July 7, 2017 at 3:46:08 PM UTC-7, Harry Potter wrote:
> On Friday, July 7, 2017 at 12:28:55 PM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
>> Yes, you have an integration bug considering the program works across multiple emulators.
> Sorry, but what _exactly_ am I doing wrong?
That's what _you_ need to spend time debugging.
FIRST, are you able to run the demo.dsk provided on GitHub ?
ONCE you have verified that works that we can proceed to troubleshoot the next step.
>> Do you have a binary and/or hexdump of your program so I can debug it?
>>
> I can give you the binary file and/or the full source. It is my Apple2SimpleIO library. My e-mail is rose(dot)joseph12(at)yahoo(dot)com.
> E-mail me for a copy. :)
Email sent.
>> Also, you don't need to manually include my source. I would simplify your cc65 assembly source to:
>>
>> .feature labels_without_colons
>> .include "print_uint16_sans_zp.s"
>>
>> That way you don't have to keep adding colons to the labels in print_uint16_sans_zp.s.
>>
>> Of course you will need to comment out the corresponding ORG and TEST code in your local copy of print_uint16_sans_zp.s
>
> I have it my way because I am developing a *library*; others need to use it, and I need a certain name for the function.
You are making it WAY harder then it needs to be. Export the name THEN include the source.
Just for your convenience I've split the demo functionality from the PrintUint16 code so that:
1) It assembles with either Merlin32 or cc65, and
2) You can include it into other projects. You shouldn't have to change a thing now in "print_uint16_sans_zp.s".
Please fetch the latest versions from GitHub.
SECOND, are you able to build `demo_cc65.s` with cc65?
- - - 8< file: demo_cc65.s - - -
..feature labels_without_colons
..export _printu
.org $800
LDA #$12
LDX #$34
JMP _printu
_printu
..include "print_uint16_sans_zp.s"
|
|
|
Re: Apple Monitor: Print Integer? [message #347766 is a reply to message #347666] |
Sat, 08 July 2017 01:11 |
barrym95838
Messages: 130 Registered: April 2013
Karma: 0
|
Senior Member |
|
|
On Thursday, July 6, 2017 at 7:56:23 PM UTC-7, Denis Molony wrote:
> I can't wait till you guys get it down to a single byte.
Only 41 bytes to go, and I'm down to one byte! :-)
300:86 A0 85 A1 A9 00 48 A9 00 A2 10 C9 05 90 02 E9
310:05 26 A0 26 A1 2A CA D0 F2 09 B0 48 A5 A0 05 A1
320:D0 E5 68 20 ED FD 68 D0 FA 60
I decided to blaze my own trail. Source available on request.
Mike B.
|
|
|
Re: Apple Monitor: Print Integer? [message #347771 is a reply to message #347766] |
Sat, 08 July 2017 02:39 |
|
Originally posted by: awanderin
barrym95838 <barrym95838@yahoo.com> writes:
> On Thursday, July 6, 2017 at 7:56:23 PM UTC-7, Denis Molony wrote:
>> I can't wait till you guys get it down to a single byte.
>
> Only 41 bytes to go, and I'm down to one byte! :-)
>
> 300:86 A0 85 A1 A9 00 48 A9 00 A2 10 C9 05 90 02 E9
> 310:05 26 A0 26 A1 2A CA D0 F2 09 B0 48 A5 A0 05 A1
> 320:D0 E5 68 20 ED FD 68 D0 FA 60
>
> I decided to blaze my own trail. Source available on request.
>
> Mike B.
Very nice! Clever way to get rid of leading zeros: don't even generate
them. :)
--
Jerry awanderin at gmail dot com
|
|
|
Re: Apple Monitor: Print Integer? [message #347775 is a reply to message #347745] |
Sat, 08 July 2017 03:49 |
|
Originally posted by: James Davis
On Friday, July 7, 2017 at 3:46:08 PM UTC-7, Harry Potter wrote:
> ... My e-mail is rose(dot)joseph12(at)yahoo(dot)com. ...
Hi Rose (AKA: Harry Potter),
Are you 12?! You should not reveal your email address to the universe as you just did. You are now vulnerable to junk mail, spam, and identity theft! You should throw that one away immediately. In future, communicate your email address (write) privately to the one person you are attempting to contact.
Sincerely,
James Davis
|
|
|
Re: Apple Monitor: Print Integer? [message #347781 is a reply to message #347775] |
Sat, 08 July 2017 07:34 |
Harry Potter
Messages: 1304 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Saturday, July 8, 2017 at 3:49:52 AM UTC-4, James Davis wrote:
> Are you 12?! You should not reveal your email address to the universe as you just did. You are now vulnerable to junk mail, spam, and identity theft! You should throw that one away immediately. In future, communicate your email address (write) privately to the one person you are attempting to contact.
>
> Sincerely,
>
> James Davis
You're right. I'm sorry. :(
|
|
|
Re: Apple Monitor: Print Integer? [message #347843 is a reply to message #347745] |
Sat, 08 July 2017 23:30 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
On Friday, July 7, 2017 at 3:46:08 PM UTC-7, Harry Potter wrote:
> On Friday, July 7, 2017 at 12:28:55 PM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
>> Yes, you have an integration bug considering the program works across multiple emulators.
> Sorry, but what _exactly_ am I doing wrong?
What YOU are doing wrong is:
[x] not running the provided demo.dsk and letting us know if it works,
[x] not writing a SMALL test case and VERIFYING that it works,
[x] not using a debugger and TRACING this YOURSELF,
[x] not telling us WHICH version of ProDOS you are using,
[x] not providing a DSK which we can boot to 100% replicate your environment,
[x] expecting other people to debug your program while not providing relevant information,
[x] keep asking trivial questions without doing any of the "groundwork" yourself, and finally
[x] In your simple.system leaving the Language Card Bank 2 active and trying to call ROM routines. Namely:
a) @ $21DF calling SCRN2+2 = $F87B
Which, on ProDOS 2.4.1 has
LC02/F87B:40 RTI
instead of the ROM expected code of LSR x4. This then causes a crash into never-never land. Depending on which version of ProDOS you have loaded will crash to different location(s),
b) @ $21EE calling PRHEXZ = $FDE5
Which would ALSO crash but it never gets here due to crashing at $21DF first.
If you want to fix this then you need to insert 3 instructions into your source:
i) 2x, BEFORE you call PrintU16 to disable LC Bank2 and re-enable ROM
STA $C081
STA $C081
ii) 2x, AFTER you call PrintU16 to re-enable LC Bank2 and disable ROM
STA $C080
STA $C080
Harry, we have been MORE then patient with you but if you refuse to help yourself you will eventually come to find that no one wants to help you.
Stop expecting other people to do your work for you.
If you don't know HOW to start to Troubleshoot then ASK.
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347851 is a reply to message #347745] |
Sun, 09 July 2017 01:21 |
Michael AppleWin Debu
Messages: 1262 Registered: March 2013
Karma: 0
|
Senior Member |
|
|
And just to PROVE what you are doing wrong is accessing the LC instead of ROM:
CALL-151
BLOAD SIMPLE.SYSTEM
23EC:8d 81 c0 8d 81 c0 86 90 A2 00 20 aa 21 8d 80 c0 8d 80 c0 60
21A6:4C EC 23
BSAVE FIXED.SYSTEM,A$2000,L$400
BE00G
-FIXED.SYSTEM
And your program will now work.
|
|
|
|
Re: Apple Monitor: Print Integer? [message #347865 is a reply to message #347843] |
Sun, 09 July 2017 09:00 |
Harry Potter
Messages: 1304 Registered: March 2012
Karma: 0
|
Senior Member |
|
|
On Saturday, July 8, 2017 at 11:30:02 PM UTC-4, Michael 'AppleWin Debugger Dev' wrote:
> What YOU are doing wrong is:
>
> [x] not running the provided demo.dsk and letting us know if it works,
I just did. It didn't work: it's only 32k long. :(
> [x] not writing a SMALL test case and VERIFYING that it works,
Well...it worked when I was using cc65's divide routine but not with your approach. :(
> [x] not using a debugger and TRACING this YOURSELF,
You got me there. :)
> [x] not telling us WHICH version of ProDOS you are using,
V. 2.0.3.
> [x] not providing a DSK which we can boot to 100% replicate your environment,
I'll e-mail it to you now. :0
> [x] expecting other people to debug your program while not providing relevant information,
I tried. What information do you need?
> [x] keep asking trivial questions without doing any of the "groundwork" yourself, and finally
You're right. :(
> [x] In your simple.system leaving the Language Card Bank 2 active and trying to call ROM routines.
>
I did elsewhere. (?)
BTW, I just got it to work. I removed the JMP PRHEXZ with a call to _printc, which prints a character to the screen and replaced the JSR SCRN2+2 with 4 lsr's. Then I had to switch .A and .X. Now it works! :) Thank you for your patience. :)
|
|
|
|
Re: Apple Monitor: Print Integer? [message #403161 is a reply to message #347496] |
Wed, 23 December 2020 15:06 |
|
Originally posted by: Joshua Bell
On Wednesday, July 5, 2017 at 5:59:50 AM UTC-7, Michael 'AppleWin Debugger Dev' wrote:
> LINPRT ... that's helluva lot of code just to print an unsigned 16-bit int.
> The only good news is that it is built-into ROM.
>
> Usage:
>
> LDA #$12
> LDX #$34
> JMP $ED24
>
> Output:
> 4660
>
> NOTE: Stack $100 .. $1104 is used as output buffer.
>
> Requires:
>
> * $E000 Basic Cold Start or
> * $E003 Basic Warm Start
>
> must be called first.
To document for posterity:
I wanted to use LINPRNT without fully initializing Basic. Assuming at least ProDOS has started (i.e. you're in a SYS file), it appears you can get away with just the following:
SHIFT.SIGN.EXT set to 0; required by FP routines
TEMPPT set to TEMPST; it's a string descriptor pointer
SPEEDZ set to 1, for no output delay
FLASH.BIT set to 0, to get normal characters
Equates per http://www.txbobsc.com/scsc/scdocumentor/definitions.html
|
|
|