EtchedPixels / CC6303

A C compiler for the 6800 series processors
Other
37 stars 7 forks source link

[question] Assembly and C? #8

Closed Fabrizio-Caruso closed 3 years ago

Fabrizio-Caruso commented 3 years ago

First of all sorry to use an issue for a question.

I would like to have a routine getk that just polls the MC-10 keyboard without waiting.

In BASIC I could just read values at 17023 and 2 to poll the keyboard. But if I use CC68 and I try to "peek" at location 17023 I do not get the ASCII code of the last key pressed. Nor does the value at 2 gets updated if any key is pressed. So I guess something is different. Maybe those values are updated by some interrupt that your crt disables.

So I suppose I need to resort to some little Assembly. I am not an Assembly coder and my best guess would be a .s file with this content:

.export _getk
.setcpu 6803

.code

_getk:
    pshx
    ldx $FFDC
    jsr ,x
    pulx
    tab
    clra
    rts

If I try to compile it, cc68 complains with multiple errors of this type: test/mc10_getk.s: 1: Q: unexpected character.

With CC65 I can compiler and link a mix for .c and .s. How do I do it with CC68?

EtchedPixels commented 3 years ago

Looks correct and works for me in fact I think it's the same code as is in target-mc10.

Are you sure you don't have any unicode order markers at the start or the wrong kind of newlines (it's not found of \r\n only the proper Unix \n).

EtchedPixels commented 3 years ago

Pushed support for legacy DOS \r\n newlines

Fabrizio-Caruso commented 3 years ago

@EtchedPixels Thanks a lot! It does work, indeed! Unfortunately it seems not to auto-repeat, i.e., if I keep a key pressed, it will just detect it once. I need to figure out how to have it auto-repeat.

P.S.: I stole your code for cgetc and I tried to adapt it for my purpose. I hope it is OK for you.

EtchedPixels commented 3 years ago

Sure.. I suspect for pure game use you may need to scan the matrix yourself.

The basic ones btw are updated by the BASIC interpreter as it runs - there is no interrupt. For some reason the 6847 vsync isn't wired through the interrupt on the 6803, instead the 6803 irq line is just pulled high.

Fabrizio-Caruso commented 3 years ago

@EtchedPixels Indeed I will have to write a scanning routine. My Assembly skills are poor. I will start with a simple C version that "pokes" at location 2 and "peeks" at 49151. It should be fast enough for my purpose. Indeed Cross-Lib is mostly meant for games and auto-repeat is necessary.

Fabrizio-Caruso commented 3 years ago

@EtchedPixels if the BASIC routine puts the ASCII value of the pressed key into 17023, couldn't I you use this routine as long as no code is stored there. How can I know where in memory your compiler stores the code? I could not find a .cfg file as in CC65.

EtchedPixels commented 3 years ago

I don't believe there is any way to just call the relevant code in the BASIC ROM - not officially anyway.

The compiler packs everything from address 17500 onwards, so just above the BASIC workspace if no BASIC program is present