GithubHelp home page GithubHelp logo

Comments (3)

jefftranter avatar jefftranter commented on August 16, 2024

Thanks for the feedback. Both this and your other suggestion look correct.
I will look further into it when I get a chance - my Replica 1 currently
isn't set up as I've been busy on some other projects. Feel free to send me
other comments, enhancements, or bug fixes.

Regards,
Jeff

On Sun, Dec 1, 2013 at 6:44 AM, DaveLyons [email protected] wrote:

Something is fishy with the "Check that start address <= end address"
code, which appears 5 times in JMON. The trouble is that either the BEQ or
the BNE must be taken (the Z flag has to be either 0 or 1!), leaving no way
to reach the "LDA SL" and the 3 lines after it.

; Check that start address <= end address
LDA SH
CMP EH
BCC @okay1
BEQ @okay1
BNE @Invalid1
LDA SL
CMP EL
BCC @okay1
BEQ @okay1
@Invalid1:
LDX #<InvalidRange
LDY #>InvalidRange
JSR PrintString
RTS

I believe the solution is to remove the (first) BEQ @okay1, because it's
when the high bytes are equal that it must consider the low bytes.

If this were packaged into a subroutine for the 5 callers, it looks like
it could save around 100 bytes. (For example, return CLC if everything is
OK; otherwise print the error string and return with SEC, to allow JSR
RequireStartNotAfterEnd + BCS BailOut.)


Reply to this email directly or view it on GitHubhttps://github.com//issues/2
.

from 6502.

DaveLyons avatar DaveLyons commented on August 16, 2024

Feel free to send me other comments, enhancements, or bug fixes.

I have 6502 code-space optimization very much on my brain lately, since I've been working on the CFFA1 v2.0 firmware, trying to keep the ProDOS support and add FAT16-with-long-filenames support, while staying within the 8K of EEPROM space.

I've made a pass scanning through all the JMON source, and I have a bunch of notes on potential ways to save code space. I'll get my notes in a presentable form for you soon, like before the weekend. -- I didn't find any more significant bugs, but I noted some places that repeated code could be shared, plus a whole bunch of "micro-optimizations" that should add up to something significant.

One of the biggest potential savings that I see would come from "inlining" most of the text, rather than having to load X and Y with a pointer to a string. I've been doing this for CFFA1, and it's great. My "DispString" (see below) preserves A/X/Y, and the inline string doesn't even have a terminating $00 byte, it has bit 7 set on the final character, instead.

The "SentinalString" macro generates a string in the necessary format, although it's awkward when there needs to be a CR at the end. In that case I use .byte and I have "CR7" defined to $8D.

jsr DispString
.byte CR
SentinelString "CFFA1> "

or
jsr DispString
.byte "ABORTED",CR7
or even a single-character string (total of 4 bytes, so it's shorter than LDA # + JSR, and it doesn't destroy A):
jsr DispString
.byte "?"+$80

The downside, of course, is that the inline strings get in the way of trying to List (er, "unassemble") the code, but in practice this hasn't bothered me much.

I noticed your "Possible Future Enhancements: ... fit in 8K" -- is there any special reason for the 8K, like running from ROM or something?

Cheers,

--Dave

I'm using ca65 v2.13.9 (no patches), so this should drop right into JMON if you want to use any part of it.

; SentinelString sets bit 7 on the final character in the string.
.macro SentinelString str
.repeat .strlen(str) - 1, i
.byte .strat(str,i)
.endrepeat
.byte .strat(str, .strlen(str) - 1) | $80
.endmacro

(If you don't need to save/restore the zero-page pointer then this doesn't need the LDA PHA LDA PHA ... PLA STA PLA STA, and the StackBase+4 and +5 become StackBase+2 and +3, in two places each.)

;------------------------------------------------------------------------------
; DispString - Sends a String to the Apple1's console
; Input:
; string must immediately follow the JSR to this function
; and be terminated with a byte that has bit 7 set.
;
; ZeroPage Usage:
; MsgPointerLow, MsgPointerHi (saved and restored)
;
; CPU Registers changed: P
;------------------------------------------------------------------------------
DispString:
pha ;save the Acc reg
txa
pha ;save the X reg
tya
pha ;save the Y reg
tsx ;put the stack pointer in X
lda MsgPointerHi
pha ;push zero page location on stack
lda MsgPointerLow
pha ;push zero page location on stack

lda StackBase+4,x            ;determine the location of message to display
clc
adc #$01                     ;add 1 because JSR pushes the last byte of its
sta MsgPointerLow            ; destination address on the stack

lda StackBase+5,x
adc #0
sta MsgPointerHi

@next:
ldy #0
lda (MsgPointerLow),y
beq @done
pha
Note, add ORA #$80 here if your "DispChar" equivalent requires it.
jsr DispChar
pla
bmi @done ; a high-bit character can terminate the string as well
inc MsgPointerLow
bne @next
inc MsgPointerHi
bne @next

@done:
lda MsgPointerHi
sta StackBase+5,x
lda MsgPointerLow
sta StackBase+4,x ;fix up the return address on the stack.

pla
sta MsgPointerLow           ;restore zero page location
pla
sta MsgPointerHi            ;restore zero page location
pla
tay
pla
tax
pla
rts                          ;return to location after string's null.

On Dec 1, 2013, at 6:31 PM, Jeff Tranter [email protected] wrote:

Thanks for the feedback. Both this and your other suggestion look correct.
I will look further into it when I get a chance - my Replica 1 currently
isn't set up as I've been busy on some other projects. Feel free to send me
other comments, enhancements, or bug fixes.

Regards,
Jeff

On Sun, Dec 1, 2013 at 6:44 AM, DaveLyons [email protected] wrote:

Something is fishy with the "Check that start address <= end address"
code, which appears 5 times in JMON. The trouble is that either the BEQ or
the BNE must be taken (the Z flag has to be either 0 or 1!), leaving no way
to reach the "LDA SL" and the 3 lines after it.

; Check that start address <= end address
LDA SH
CMP EH
BCC @okay1
BEQ @okay1
BNE @Invalid1
LDA SL
CMP EL
BCC @okay1
BEQ @okay1
@Invalid1:
LDX #<InvalidRange
LDY #>InvalidRange
JSR PrintString
RTS

I believe the solution is to remove the (first) BEQ @okay1, because it's
when the high bytes are equal that it must consider the low bytes.

If this were packaged into a subroutine for the 5 callers, it looks like
it could save around 100 bytes. (For example, return CLC if everything is
OK; otherwise print the error string and return with SEC, to allow JSR
RequireStartNotAfterEnd + BCS BailOut.)


Reply to this email directly or view it on GitHubhttps://github.com//issues/2
.


Reply to this email directly or view it on GitHub.

from 6502.

jefftranter avatar jefftranter commented on August 16, 2024

I made the fix as well as factoring the code out into a separate subroutine.

from 6502.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.