Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

at-xy #438

Open
lonetech opened this issue Jul 6, 2022 · 15 comments
Open

at-xy #438

lonetech opened this issue Jul 6, 2022 · 15 comments

Comments

@lonetech
Copy link
Contributor

lonetech commented Jul 6, 2022

I didn't see where in the library at-xy was, so I cobbled one together using kernal plot:

: at-xy xr c! yr c! 0 sr c! $fff0 sys ;

Do you think it might be worth including somewhere?

It doesn't preserve interrupt disable, which might be something to improve. In assembly it would use CLC.

The routine itself would be grouped with page and emit, so I guess the norm here is assembly routines in io.asm.
I did the exercise to convert to code:

code at-xy ( x y -- )
  clc,
  w stx,
  \ w 1+ sty,
  lsb 1+ ldy,x
  lsb lda,x  \ had no ldx,x
  tax,
  $fff0 jsr,
  w ldx,
  \ w 1+ ldy,
  inx,
  inx,
;code

That also worked. It's rather cumbersome code, though, mostly dealing with ABI conversion. Still size reports the code version as smaller than the sys version.

Evidently, I am a total newbie at 6502 assembly.

@Whammo
Copy link
Collaborator

Whammo commented Jul 6, 2022

Nice work!
I can't speak for the repositor, but I believe that unless a routine is required for compiling the build, it's inclusion into the codebase is contraindicated.
That's not to say that submissions are unwelcome. Durexforth acquires great power very easily. I think it's the C64's best kept secret.

@jkotlinski
Copy link
Owner

Nice! Maybe it would fit in compat.fs as an optional include?

@lonetech
Copy link
Contributor Author

It does fit the compat.fs pattern as a word with standard functionality that isn't currently in use. I'd be quite happy with that.

@Whammo
Copy link
Collaborator

Whammo commented Jul 21, 2022

Perhaps it's corollary would also be appropriate? XY-AT ? XY@ ? PLOT ?

EDIT: SETCUR in V.fs is this, but uses SYS?

@Whammo
Copy link
Collaborator

Whammo commented Jul 21, 2022

: setcur ( x y -- )  \ hidden in v
xr ! yr ! $e50c sys ; 

vs.

code setcur ( x y -- )
   lsb lda,x
       inx,
   lsb ldy,x
       inx,
     w stx,
       tax,
 $e50c jsr,
     w ldx,
;code


@lonetech
Copy link
Contributor Author

lonetech commented Jul 21, 2022

That's jumping inside the PLOT routine, to the set part. The $fff0 vector points to $e50a, which presumably does a branch if the carry flag is set (bcs) before falling through to $e50c. This sort of shortcut might make it incompatible with e.g. Commodore 128 80-column mode.

It is a significant find, though. It may make sense to change its name to at-xy and unhide it.

@Whammo
Copy link
Collaborator

Whammo commented Jul 22, 2022

Fun, fun, fun!

: setcur ( x y -- )  \ hidden in v
xr ! yr ! $e50c sys ;

code at-xy ( x y -- )
   lsb lda,x
       inx,
   lsb ldy,x
       inx,
     w stx,
       tax,
 $e50c jsr,
     w ldx,
;code

size setcur \ 20
size at-xy  \ 15

@jkotlinski
Copy link
Owner

A pull request with this addition would be welcome. I suppose it should be added to documentation and changelog, too.

@VOC-LINK
Copy link

Guys, three things:

1 It can be done much simpler way on good old C-64:
: get-xy ( – x y ) 211 c@ 214 c@ ;
: goto-xy ( x y – ) 214 c! 211 c! ;

  1. The name at-xy fits better the word „get character code at X, Y on the screen” ( at-xy ( x y — char ) ).
  2. There's no need to include everything anyone finds useful; it's Forth! The users include the words by themselves.

@Whammo
Copy link
Collaborator

Whammo commented Nov 10, 2022

This doesn't set the screen pointers properly,

: goto-xy ( x y – ) 214 c! 211 c! ;

@VOC-LINK
Copy link

Alas, you're right; X works OK, but Y (214) seems to make sense just as read-only. Probably during my quick-check I used the value that moved cursor into the current line and on first glance it looked OK.

@Whammo
Copy link
Collaborator

Whammo commented Nov 10, 2022

It's great fun to jump into the Kernal.

: goto-xy ( x y – ) 214 c! 211 c! $e56c sys ;

: goto-xy ( x y -- ) 214 c! 211 c!
$e56c sys ;

: try page
40 0 do 25 0 do j i goto-xy
118 emit loop
loop ;

@VOC-LINK
Copy link

Indeed. I have to admit my second mistake: since Durex Forth strives to be ANS-standard compliant, that word has to be named AT-XY, unfortunately, not GOTO-XY, But my new proposal for the name of „a word, that returns character code at X, Y” is XY@ ( x y -- char ) (on PC it would return character code and attribute byte).

@VOC-LINK
Copy link

VOC-LINK commented Nov 12, 2022

Its code will be rather simple:
: XY@ ( x y -- charcode ) 40 * + 53272 C@ 16 / 1024 * + C@ ;

@Whammo
Copy link
Collaborator

Whammo commented Nov 12, 2022

It is fun to not presume from where screen memory may be obtained. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants