Jump to content

JimmyDansbo

Moderators
  • Posts

    298
  • Joined

  • Last visited

  • Days Won

    9

Posts posted by JimmyDansbo

  1. On 1/12/2022 at 9:30 PM, desertfish said:

    I think it's usable from basic as well

    Unfortunately it is not well suited to be used by BASIC. I have just fiddled around a bit with it to see if I could make it usable from BASIC but I seem to run into strange behavior where the emulator just hangs... That is not an issue I have seen when it is used from assembler programs.

    • Like 1
  2. On 12/30/2021 at 7:16 PM, svenvandevelde said:

    How can I identify the ROM version in C? Which adres to peek?

    You read from Addres $FF80 in ROM bank 0

    Quote

    *=$0801
    !byte $0C,$08,$0A,$00,$9E,' ','2','0','6','4',$00,$00,$00
    *=$0810

    KERNELVER    = $FF80
    main:
        lda    $01
        tay        ; Save current ROM
        lda    #0
        sta    $01    ; Set ROM bank = 0
        lda    KERNELVER    ; Read kernel version
        sty    $01    ; Restore ROM Bank

        rts
     

    https://github.com/commanderx16/x16-docs/blob/master/Commander X16 Programmer's Reference Guide.md#kernal-version

    • Thanks 1
  3. On 11/16/2021 at 5:30 AM, kelli217 said:

    You could try using the KERNAL routine for plotting the cursor position.

    Yes, that is also possible however it requires that you set the carry flag before calling it to get it to return the actual coordinates.

    Something like this one-liner should work

    Quote

    POKE 783,1:SYS $FFF0:PRINT PEEK(781)

    Address 780-783 are the CPU registers and flags just as the Commodore 64, see https://www.c64-wiki.com/wiki/SYS

    $FFF0 is the kernal PLOT routine, see https://cx16.dk/c64-kernal-routines/plot.html

    You do not have to switch ROM as the BASIC ROM does indeed have stubs to forward calls to the Kernal ROM just as @Scott Robison mentioned.

    Above line will of course use more CPU cycles than a simple peek of a memory address, but you should be fairly certain that the addresses do not change.

    • Like 3
  4. On 11/9/2021 at 5:17 PM, Stefan said:

    Some time ago, I made a pull request for a new BASIC command "FSYS" to invoke code in other ROM banks.

    As the X16 kernal is based off of the C64 kernal, it might be an idea to look at the big-brother for how they handled banking.

    Instead of an FSYS command, maybe we should implement something similar to the BANK command from BASIC 7 https://www.c64-wiki.com/wiki/BANK

    According to the C128 programmers reference https://www.pagetable.com/docs/Commodore 128 Programmer's Reference Guide.pdf (page 28 / 38), SYS, PEEK, POKE and WAIT will then use the selected bank.

    • Like 2
  5. 59903 = $E9FF

    Looking at https://www.pagetable.com/c64ref/c64disasm/ I found that address to be the start of a function called CLRLN (Clear Line).

    Then I looked through the X16 source code to find the CLRLN function, but it does not exist instead I found the screen_clear_line function and looking at the .sym files I found the entry address of $C88E

    Unfortunately BASIC lives in ROM bank 4 and the screen_clear_line function is in ROM bank 0 so it is not possible to call it directly without switching banks. I tried switching banks in BASIC by poking the VIA, but as soon as the bank is switched, BASIC is no longer able to run and the emulator hangs (of course).

    I have written a small program that actually calls the screen_clear_line functions and ensures that the ROM banks selection is correct, but it might be just as easy to just clear the line through ordinary BASIC code.

    Quote

    10 DATA $9C,$60,$9F,$20,$8E,$C8,$A9,$04,$8D,$60,$9F,$60
    20 FORI=$400TO$40B:READ A:POKEI,A:NEXT
    30 POKE 781,2:SYS$400

    Line 10 is actually a small machine language program that sets the ROM bank to 0, calls the screen_clear_line function and sets the ROM bank back to 4 before returning.

    Line 20 Writes the machine language program to RAM address $400 (golden RAM)

    Line 30 Sets the line that should be cleared and calls the machine language function.

    This is the disassembly of the machine language program in line 10:

    Quote

    STZ $9F60
    JSR $C88E
    LDA #$04
    STA $9F60
    RTS

    Note that when R39 of the ROM is released, this code will no longer work as the bank switching is moved down to zero-page.

    • Like 1
    • Thanks 1
  6. On 10/8/2021 at 12:08 PM, snake said:

    I'm think DB may work for !BYTE,!PET,!SCR

    DB will definitely work for !BYTE, but ACME tries to ensure that things that are defined as !PET or !SCR gets put into memory in such a way that characters typed in the source is the same when assembled and run on the target computer. You can you use DB instead of !PET and !SCR, but then you will need to ensure that correct conversion of characters is done. Your assembler may have other ways of storing strings.

  7. !BYTE, !PET & !SCR looks to me like they are pseudo opcodes used by the ACME assembler. You would have to look up the equivalent codes for the assembler you are using for the Z80.

    There is no way of directly translating CPY and CPX to Z80 assembly, but the Z80 has its own compare instructions: http://z80-heaven.wikidot.com/instructions-set:cp

    disclaimer: I am by no means fluent in Z80 assembly and had to look up the CP instruction before I could write this reply.

  8. 8 hours ago, rje said:

    b ram 4

    m a000 (actually, this command appears to ignore the bank set and always displays bank 0)

    To switch bank, you just insert the bank number before the memory address, so to see address A000 in bank 4 you do

    Quote

    m 4a000

    Same thing works for the code view, which is helpful if you want to step through kernal calls

    Quote

    d 4ffe4

     

  9. A while back, my brother told me that he would like to create a program for the Commander X16 that would be able to convert a program/game written for the Commodore 64 to make it run on the Commander X16.

    Preferably, it would do the conversion on the fly, but a conversion from file to file was not out of the question.

    I told him that it would be close to impossible to create such a program as it would mean that he would need 100% understanding of the inner workings of the C64 and be able to figure every demo-scene programmers tricks out in his own program.

    Our conversation ended there, but I have been thinking about this ever since and now I have written a short guide (mostly to convince my self that it can not be done) on how one could go ahead and do it.

    Have a look at https://techblog.dansbo.dk/?p=366

    What do you guys think, would it be possible to create a program that can convert almost any C64 program to Commander X16?

  10. You can use PETSCII codes to set both background and foreground color.

    Something like this:

    Quote

    10 PRINT CHR$($81):REM SET FOREGROUND COLOR TO ORANGE
    20 PRINT CHR$($01):REM SWAP FOREGROUND- AND BACKGROUND COLOR
    30 PRINT CHR$($1F):REM SET FOREGROUND COLOR TO BLUE
    40 PRINT "THIS TEXT IS BLUE ON ORANGE BACKGROUND"

    You can find a table of the PETSCII codes here: https://cx16.dk/cx16-petscii/

    If you are writing directly to VERA memory, you need to remember that in default text modes, each character on screen uses 2 bytes of VRAM.

    The first byte contains the screencode of the character and the second byte contains the bacground- and foreground color.

    So you write to VRAM like this:

    Quote

    10 VPOKE 0,0,0         :REM DISPLAY AN @ SIGN AT COORDINATE 0,0
    20 VPOKE 0,1,$51       :REM MAKE IT WHITE ON GREEN
    30 VPOKE 0,(10*2)+(256*1),0:REM PRINT AN @ AT COORDINATE 10,1
    40 VPOKE 0,(10*2)+(256*1)+1,$51:REM WHITE ON GREEN AGAIN

    You can find a table of screencodes and VERA standard colors here: https://cx16.dk/veratext/verachars/

    When you use VPOKE to write to VRAM, you have to calculate the addresses your self, but it is fairly easy.

    Your X coordinate should always be doubled as each character on screen takes up 2 bytes. This is why I have (10*2) on line 30 and 40 above to make the @ sign appear at X=10.

    Each line takes up 256 bytes of VRAM even though only 80 (or 40) characters are visible so in order to calculated your Y coordinate you simply multiply it by 256.

    The final calculation is:

    Quote

    (Xcoordinate*2)+(Ycoordinate*256) = Character on screen
    (Xcoordinate*2)+(Ycoordinate*256)+1 = Color of character on screen

    The color information is most easily given in hexadecimal as that means that the first digit (upper nibble) is the background color and the second digit (lower nibble) is the foreground color. For more information on VPOKE, have a look at the manual: https://github.com/commanderx16/x16-docs/blob/master/Commander X16 Programmer's Reference Guide.md#vpoke

     

    • Like 1
×
×
  • Create New...

Important Information

Please review our Terms of Use