From 3ea0ded65d59717d7f7e1454bacbd53baac505de Mon Sep 17 00:00:00 2001 From: xlar54 Date: Wed, 12 Jun 2024 16:23:30 -0500 Subject: [PATCH 01/22] initial --- libsrc/cx16/tgi/cx640p1.s | 664 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 664 insertions(+) create mode 100644 libsrc/cx16/tgi/cx640p1.s diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s new file mode 100644 index 000000000..1fcceecf8 --- /dev/null +++ b/libsrc/cx16/tgi/cx640p1.s @@ -0,0 +1,664 @@ +; +; Graphics driver for the 640 pixels across, 480 pixels down, 2 color mode +; on the Commander X16 +; +; 2024-06-11, Scott Hutter +; Based on code by Greg King +; + + .include "zeropage.inc" + + .include "tgi-kernel.inc" + .include "tgi-error.inc" + + .include "cbm_kernal.inc" + .include "cx16.inc" + + .macpack generic + .macpack module + + +; Macro that copies a word into a pseudo-register + +.mac setReg reg, src + lda src + ldx src+1 + sta gREG::reg + stx gREG::reg+1 +.endmac + + +; ------------------------------------------------------------------------ +; Header. Includes jump table and constants. + + module_header _cx640p1_tgi ; 640 pixels across, 1 pixel per byte + +; First part of the header is a structure that has a signature, +; and defines the capabilities of the driver. + + .byte $74, $67, $69 ; ASCII "tgi" + .byte TGI_API_VERSION ; TGI API version number + .addr $0000 ; Library reference + .word 640 ; X resolution + .word 480 ; Y resolution + .byte 2 ; Number of drawing colors + .byte 0 ; Number of screens available + .byte 8 ; System font X size + .byte 8 ; System font Y size + .word $0100 ; Aspect ratio (based on VGA display) + .byte 0 ; TGI driver flags + +; Next, comes the jump table. Currently, all entries must be valid, +; and may point to an RTS for test versions (function not implemented). + + .addr INSTALL + .addr UNINSTALL + .addr INIT + .addr DONE + .addr GETERROR + .addr CONTROL + .addr CLEAR + .addr SETVIEWPAGE + .addr SETDRAWPAGE + .addr SETCOLOR + .addr SETPALETTE + .addr GETPALETTE + .addr GETDEFPALETTE + .addr SETPIXEL + .addr GETPIXEL + .addr LINE + .addr BAR + .addr TEXTSTYLE + .addr OUTTEXT + + +; ------------------------------------------------------------------------ +; Constant + + + +; ------------------------------------------------------------------------ +; Data. + +; Variables mapped to the zero page segment variables. Some of these are +; used for passing parameters to the driver. + +X1 = ptr1 +Y1 = ptr2 +X2 = ptr3 +Y2 = ptr4 + +ADDR = tmp1 ; ADDR+1,2,3 + +TEMP = tmp3 +TEMP2 = tmp4 ; HORLINE +TEMP3 = sreg ; HORLINE + +tempX: +.byte $00, $00 +tempY: +.byte $00, $00 + +ERR2: +.byte $00 +ERR: +.byte $00 +SY: +.byte $00 +SX: +.byte $00 +DY: +.byte $00 +DX: +.byte $00 +CURRENT_Y: +.byte $00, $00 +CURRENT_X: +.byte $00, $00 +; Absolute variables used in the code + +.bss + +; The colors are indicies into a TGI palette. The TGI palette is indicies into +; VERA's palette. Vera's palette is a table of Red, Green, and Blue levels. +; The first 16 RGB elements mimic the Commodore 64's colors. + +SCRBASE: .res 1 ; High byte of screen base +BITMASK: .res 1 ; $00 = clear, $FF = set pixels +OLDCOLOR: .res 1 ; colors before entering gfx mode + +defpalette: .res $0100 +palette: .res $0100 + +bcolor := palette + 0 ; Background color +color: .res 1 ; Stroke and fill index +text_mode: .res 1 ; Old text mode + +.data + +error: .byte TGI_ERR_OK ; Error code + + +; Constants and tables + +.rodata + +; Bit masks for setting pixels +bitMasks1: + .byte %10000000, %01000000, %00100000, %00010000 + .byte %00001000, %00000100, %00000010, %00000001 +bitMasks2: + .byte %01111111, %10111111, %11011111, %11101111 + .byte %11110111, %11111011, %11111101, %11111110 + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. May +; initialize anything that has to be done just once. Is probably empty +; most of the time. +; +; Must set an error code: NO + +INSTALL: +; Create the default palette. + + ldx #$00 +: txa + sta defpalette,x + inx + bnz :- + + ; Fall through. + +; ------------------------------------------------------------------------ +; UNINSTALL routine. Is called before the driver is removed from memory. May +; clean up anything done by INSTALL, but is probably empty most of the time. +; +; Must set an error code: NO + +UNINSTALL: + rts + +; ------------------------------------------------------------------------ +; INIT: Changes an already installed device from text mode to graphics +; mode. +; Note that INIT/DONE may be called multiple times while the driver +; is loaded, while INSTALL is called only once; so, any code that is needed +; to initiate variables and so on must go here. Setting the palette is not +; needed because that is called by the graphics kernel later. +; The graphics kernel never will call INIT when a graphics mode already is +; active, so there is no need to protect against that. +; +; Must set an error code: YES + +INIT: stz error ; #TGI_ERR_OK + +; Save the current text mode. + + sec + jsr SCREEN_MODE + sta text_mode + +; Switch into (640 x 480 x 2) graphics mode. + + lda #%00000000 ; DCSEL = 0, VRAM port 1 + sta VERA::CTRL + lda #%00100001 ; Disable sprites, layer 1 enable, VGA + sta VERA::DISP::VIDEO + lda #%00000100 ; Bitmap mode enable + sta VERA::L1::CONFIG + lda #%00000001 ; Tile width 640 + sta VERA::L1::TILE_BASE + rts + +; ------------------------------------------------------------------------ +; DONE: Will be called to switch the graphics device back into text mode. +; The graphics kernel never will call DONE when no graphics mode is active, +; so there is no need to protect against that. +; +; Must set an error code: NO + +DONE: + jsr CINT + lda text_mode + clc + jmp SCREEN_MODE + +; ------------------------------------------------------------------------ +; GETERROR: Return the error code in .A, and clear it. + +GETERROR: + lda error + stz error + rts + +; ------------------------------------------------------------------------ +; CONTROL: Platform-/driver-specific entry point. +; +; Must set an error code: YES + +CONTROL: + lda #TGI_ERR_INV_FUNC + sta error + rts + +; ------------------------------------------------------------------------ +; CLEAR: Clear the screen. +; +; Must set an error code: NO + +CLEAR : + .scope inner + + ; set up DCSEL=2 + lda #(2 << 1) + sta VERA::CTRL + + ; set cache writes + lda #$40 + tsb $9f29 ;VERA_FX_CTRL + + ; set FX cache to all zeroes + lda #(6 << 1) + sta VERA::CTRL + + lda #$00 ; color + ; $00=black, $01=white + beq ahead + lda #$ff +ahead: + sta VERA::DISP::VIDEO + sta VERA::DISP::HSCALE ;$9f2a + sta VERA::DISP::VSCALE ;$9f2b + sta VERA::DISP::FRAME ;$9f2c + + stz VERA::CTRL + ; set address and increment for bitmap area + stz VERA::ADDR + stz VERA::ADDR + 1 + lda #$30 ; increment +4 + sta VERA::ADDR + 2 + + ldy #240 ; number of rows +blank_outer: + ldx #10 ; 10 iterations of 32 = one line of 320 at 8bpp +blank_loop: + + .repeat 8 + stz VERA::DATA0 ; $9f23 each `stz` writes four zeroes to VRAM (cache contents) for a total of 32 pixels when repeated 8x + .endrep + + dex + bne blank_loop + dey + bne blank_outer + + ; set up DCSEL=2 + lda #(2 << 1) + sta VERA::CTRL ; $9f25 + + ; set FX off (cache write bit 1 -> 0) + stz $9f29 ;VERA_FX_CTRL + stz VERA::CTRL + + .endscope + rts + + +; ------------------------------------------------------------------------ +; SETVIEWPAGE: Set the visible page. Called with the new page in .A (0..n-1). +; The page number already is checked to be valid by the graphics kernel. +; +; Must set an error code: NO (will be called only if page OK) + +SETVIEWPAGE: + + ; Fall through. + +; ------------------------------------------------------------------------ +; SETDRAWPAGE: Set the drawable page. Called with the new page in .A (0..n-1). +; The page number already is checked to be valid by the graphics kernel. +; +; Must set an error code: NO (will be called only if page OK) + +SETDRAWPAGE: + rts + +; ------------------------------------------------------------------------ +; SETPALETTE: Set the palette (not available with all drivers/hardware). +; A pointer to the palette is passed in ptr1. Must set an error if palettes +; are not supported +; +; Must set an error code: YES + +SETPALETTE: + stz error ; #TGI_ERR_OK + ldy #$00 +: lda (ptr1),y + sta palette,y + iny + bnz :- + + lda color ; Get stroke and fill index + + ; Fall through. + +; ------------------------------------------------------------------------ +; SETCOLOR: Set the drawing color (in .A). The new color already is checked +; to be in a valid range (0..maxcolor). +; +; Must set an error code: NO (will be called only if color OK) + +SETCOLOR: + tax + beq @L1 + lda #$FF +@L1: sta BITMASK + rts + +; ------------------------------------------------------------------------ +; GETPALETTE: Return the current palette in .XA. Even drivers that cannot +; set the palette should return the default palette here, so there's no +; way for this function to fail. +; +; Must set an error code: NO + +GETPALETTE: + lda #palette + rts + +; ------------------------------------------------------------------------ +; GETDEFPALETTE: Return the default palette for the driver in .XA. All +; drivers should return something reasonable here, even drivers that don't +; support palettes, otherwise the caller has no way to determine the colors +; of the (not changable) palette. +; +; Must set an error code: NO (all drivers must have a default palette) + +GETDEFPALETTE: + lda #defpalette + rts + +; ------------------------------------------------------------------------ +; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing +; color. The co-ordinates passed to this function never are outside the +; visible screen area, so there is no need for clipping inside this function. +; +; Must set an error code: NO + +SETPIXEL: + jsr CALC + + stx TEMP + + lda ADDR + ldy ADDR+1 + ldx #$00 + + sta VERA::ADDR + sty VERA::ADDR + 1 + stx VERA::ADDR + 2 + + ldx TEMP + + lda BITMASK + beq @ahead + + ; if COLOR = 1, white is line color + ; Set the bit in the byte at VERA_DATA0 + lda VERA::DATA0 ; Load the byte at memory address + ora bitMasks1,X ; OR with the bit mask + ;lda 0 + sta VERA::DATA0 ; Store back the modified byte + rts + + @ahead: + ; if COLOR = 0, black is line color + lda VERA::DATA0 ; Load the byte at memory address + and bitMasks2,X ; OR with the bit mask + sta VERA::DATA0 ; Store back the modified byte + rts + +; ------------------------------------------------------------------------ +; GETPIXEL: Read the color value of a pixel, and return it in .XA. The +; co-ordinates passed to this function never are outside the visible screen +; area, so there is no need for clipping inside this function. + +GETPIXEL: + jsr CALC + + stx TEMP + + lda ADDR + ldy ADDR+1 + ldx #$00 + + sta VERA::ADDR + sty VERA::ADDR + 1 + stx VERA::ADDR + 2 + + ldx TEMP + lda VERA::DATA0 ; Load the byte at memory address + and bitMasks1,X + + bne @ahead + + ldx #$00 + lda #$00 + rts + + @ahead: + ldx #$00 + lda #$01 + rts + +; ------------------------------------------------------------------------ +; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where +; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4, using the current drawing color. +; Contrary to most other functions, the graphics kernel will sort and clip +; the co-ordinates before calling the driver; so on entry, the following +; conditions are valid: +; X1 <= X2 +; Y1 <= Y2 +; (X1 >= 0) && (X1 < XRES) +; (X2 >= 0) && (X2 < XRES) +; (Y1 >= 0) && (Y1 < YRES) +; (Y2 >= 0) && (Y2 < YRES) +; +; Must set an error code: NO + +BAR: + ; Initialize tempY with Y1 + LDA Y1 + STA tempY + LDA Y1+1 + STA tempY+1 + +@outer_loop: + ; Compare tempY with Y2 + LDA tempY+1 + CMP Y2+1 + BCC @outer_continue ; If tempY high byte < Y2 high byte, continue + BNE @outer_end ; If tempY high byte > Y2 high byte, end + LDA tempY + CMP Y2 + BCC @outer_continue ; If tempY low byte < Y2 low byte, continue + BEQ @outer_end ; If tempY low byte = Y2 low byte, end + +@outer_continue: + ; Initialize tempX with X1 + LDA X1 + STA tempX + LDA X1+1 + STA tempX+1 + +@inner_loop: + ; Compare tempX with X2 + LDA tempX+1 + CMP X2+1 + BCC @inner_continue ; If tempX high byte < X2 high byte, continue + BNE @inner_end ; If tempX high byte > X2 high byte, end + LDA tempX + CMP X2 + BCC @inner_continue ; If tempX low byte < X2 low byte, continue + +@inner_end: + ; Increment tempY + INC tempY + BNE @outer_loop ; If no overflow, continue outer loop + INC tempY+1 ; If overflow, increment high byte + +@inner_continue: + ; Call setpixel(tempX, tempY) + LDA X1 + PHA + LDA X1+1 + PHA + LDA Y1 + PHA + LDA Y1+1 + PHA + + LDA tempX + LDX tempX+1 + STA X1 + STX X1+1 + + LDA tempY + LDX tempY+1 + STA Y1 + STX Y1+1 + + JSR SETPIXEL + + PLA + STA Y1+1 + PLA + STA Y1 + PLA + STA X1+1 + PLA + STA X1 + + ; Increment tempX + INC tempX + BNE @inner_loop_check ; If no overflow, continue + INC tempX+1 ; If overflow, increment high byte + +@inner_loop_check: + ; Compare tempX with X2 again after increment + LDA tempX+1 + CMP X2+1 + BCC @inner_continue ; If tempX high byte < X2 high byte, continue + BNE @outer_increment ; If tempX high byte > X2 high byte, increment tempY + LDA tempX + CMP X2 + BCC @inner_continue ; If tempX low byte < X2 low byte, continue + +@outer_increment: + ; Increment tempY + INC tempY + BNE @outer_loop ; If no overflow, continue outer loop + INC tempY+1 ; If overflow, increment high byte + +@outer_end: + ; End of outer loop, continue with program + JMP @done + +@done: + ; Continue with your program + +; ------------------------------------------------------------------------ +; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y +; directions are passed in .X and .Y, the text direction is passed in .A. +; +; Must set an error code: NO + +TEXTSTYLE: + rts + +; ------------------------------------------------------------------------ +; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the +; current text style. The text to output is given as a zero-terminated +; string with address in ptr3. +; +; Must set an error code: NO + +OUTTEXT: + jsr Point + + ldy #$00 +@next: lda (ptr3),y + bze @end + phy + jsr GRAPH_PUT_CHAR + ply + iny + bnz @next +@end: rts + +; ------------------------------------------------------------------------ +; Point: Set the arguments for the first point of a Kernal graphics function. + +Point: setReg r0, X1 + setReg r1, Y1 + rts + + +; ------------------------------------------------------------------------ +; Calculate all variables to plot the pixel at X1/Y1. +;------------------------ +;< X1,Y1 - pixel +;> ADDR - address of card +;> X - bit number (X1 & 7) +CALC: + lda Y1+1 + sta ADDR+1 + lda Y1 + asl + rol ADDR+1 + asl + rol ADDR+1 ; Y*4 + clc + adc Y1 + sta ADDR + lda Y1+1 + adc ADDR+1 + sta ADDR+1 ; Y*4+Y=Y*5 + lda ADDR + asl + rol ADDR+1 + asl + rol ADDR+1 + asl + rol ADDR+1 + asl + rol ADDR+1 + sta ADDR ; Y*5*16=Y*80 + lda X1+1 + sta TEMP + lda X1 + lsr TEMP + ror + lsr TEMP + ror + lsr TEMP + ror + clc + adc ADDR + sta ADDR + lda ADDR+1 ; ADDR = Y*80+x/8 + adc TEMP + sta ADDR+1 + lda ADDR+1 + lda X1 + and #7 + tax + rts + + +.include "../../tgi/tgidrv_line.inc" \ No newline at end of file From 2c4aca43dfa5d44bc6f0546fd3b402773de3750e Mon Sep 17 00:00:00 2001 From: xlar54 Date: Wed, 12 Jun 2024 16:40:23 -0500 Subject: [PATCH 02/22] fixed some text alignment --- libsrc/cx16/tgi/cx640p1.s | 149 +++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 1fcceecf8..8f3777b16 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -472,105 +472,104 @@ GETPIXEL: ; Must set an error code: NO BAR: - ; Initialize tempY with Y1 - LDA Y1 - STA tempY - LDA Y1+1 - STA tempY+1 + ; Initialize tempY with Y1 + lda Y1 + sta tempY + lda Y1+1 + sta tempY+1 @outer_loop: - ; Compare tempY with Y2 - LDA tempY+1 - CMP Y2+1 - BCC @outer_continue ; If tempY high byte < Y2 high byte, continue - BNE @outer_end ; If tempY high byte > Y2 high byte, end - LDA tempY - CMP Y2 - BCC @outer_continue ; If tempY low byte < Y2 low byte, continue - BEQ @outer_end ; If tempY low byte = Y2 low byte, end + ; Compare tempY with Y2 + lda tempY+1 + cmp Y2+1 + bcc @outer_continue ; If tempY high byte < Y2 high byte, continue + bne @outer_end ; If tempY high byte > Y2 high byte, end + lda tempY + cmp Y2 + bcc @outer_continue ; If tempY low byte < Y2 low byte, continue + beq @outer_end ; If tempY low byte = Y2 low byte, end @outer_continue: - ; Initialize tempX with X1 - LDA X1 - STA tempX - LDA X1+1 - STA tempX+1 + ; Initialize tempX with X1 + lda X1 + sta tempX + lda X1+1 + sta tempX+1 @inner_loop: - ; Compare tempX with X2 - LDA tempX+1 - CMP X2+1 - BCC @inner_continue ; If tempX high byte < X2 high byte, continue - BNE @inner_end ; If tempX high byte > X2 high byte, end - LDA tempX - CMP X2 - BCC @inner_continue ; If tempX low byte < X2 low byte, continue + ; Compare tempX with X2 + lda tempX+1 + cmp X2+1 + bcc @inner_continue ; If tempX high byte < X2 high byte, continue + bne @inner_end ; If tempX high byte > X2 high byte, end + lda tempX + cmp X2 + bcc @inner_continue ; If tempX low byte < X2 low byte, continue @inner_end: - ; Increment tempY - INC tempY - BNE @outer_loop ; If no overflow, continue outer loop - INC tempY+1 ; If overflow, increment high byte + ; Increment tempY + inc tempY + bne @outer_loop ; If no overflow, continue outer loop + inc tempY+1 ; If overflow, increment high byte @inner_continue: - ; Call setpixel(tempX, tempY) - LDA X1 - PHA - LDA X1+1 - PHA - LDA Y1 - PHA - LDA Y1+1 - PHA + ; Call setpixel(tempX, tempY) + lda X1 + pha + lda X1+1 + pha + lda Y1 + pha + lda Y1+1 + pha - LDA tempX - LDX tempX+1 - STA X1 - STX X1+1 + lda tempX + ldx tempX+1 + sta X1 + stx X1+1 - LDA tempY - LDX tempY+1 - STA Y1 - STX Y1+1 + lda tempY + ldx tempY+1 + sta Y1 + stx Y1+1 - JSR SETPIXEL + jsr SETPIXEL - PLA - STA Y1+1 - PLA - STA Y1 - PLA - STA X1+1 - PLA - STA X1 + pla + sta Y1+1 + pla + sta Y1 + pla + sta X1+1 + pla + sta X1 ; Increment tempX - INC tempX - BNE @inner_loop_check ; If no overflow, continue - INC tempX+1 ; If overflow, increment high byte + inc tempX + bne @inner_loop_check ; If no overflow, continue + inc tempX+1 ; If overflow, increment high byte @inner_loop_check: - ; Compare tempX with X2 again after increment - LDA tempX+1 - CMP X2+1 - BCC @inner_continue ; If tempX high byte < X2 high byte, continue - BNE @outer_increment ; If tempX high byte > X2 high byte, increment tempY - LDA tempX - CMP X2 - BCC @inner_continue ; If tempX low byte < X2 low byte, continue + ; Compare tempX with X2 again after increment + lda tempX+1 + cmp X2+1 + bcc @inner_continue ; If tempX high byte < X2 high byte, continue + bne @outer_increment ; If tempX high byte > X2 high byte, increment tempY + lda tempX + cmp X2 + bcc @inner_continue ; If tempX low byte < X2 low byte, continue @outer_increment: - ; Increment tempY - INC tempY - BNE @outer_loop ; If no overflow, continue outer loop - INC tempY+1 ; If overflow, increment high byte + ; Increment tempY + inc tempY + bne @outer_loop ; If no overflow, continue outer loop + inc tempY+1 ; If overflow, increment high byte @outer_end: - ; End of outer loop, continue with program - JMP @done + jmp @done @done: - ; Continue with your program + rts ; ------------------------------------------------------------------------ ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y From 91cdc0d70542244a3874d5ba3e36917e130465a6 Mon Sep 17 00:00:00 2001 From: xlar54 Date: Wed, 12 Jun 2024 16:45:24 -0500 Subject: [PATCH 03/22] removed unneeded code --- libsrc/cx16/tgi/cx640p1.s | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 8f3777b16..110edba4a 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -18,20 +18,10 @@ .macpack module -; Macro that copies a word into a pseudo-register - -.mac setReg reg, src - lda src - ldx src+1 - sta gREG::reg - stx gREG::reg+1 -.endmac - - ; ------------------------------------------------------------------------ ; Header. Includes jump table and constants. - module_header _cx640p1_tgi ; 640 pixels across, 1 pixel per byte + module_header _cx640p1_tgi ; 640 pixels across, 1 pixel per bit ; First part of the header is a structure that has a signature, ; and defines the capabilities of the driver. @@ -588,23 +578,6 @@ TEXTSTYLE: ; Must set an error code: NO OUTTEXT: - jsr Point - - ldy #$00 -@next: lda (ptr3),y - bze @end - phy - jsr GRAPH_PUT_CHAR - ply - iny - bnz @next -@end: rts - -; ------------------------------------------------------------------------ -; Point: Set the arguments for the first point of a Kernal graphics function. - -Point: setReg r0, X1 - setReg r1, Y1 rts From ff5091202f3022751912762567a3838bb9c3509c Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 21:00:40 -0500 Subject: [PATCH 04/22] docs --- doc/cx16.sgml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/cx16.sgml b/doc/cx16.sgml index 78a51206b..a718e52fa 100644 --- a/doc/cx16.sgml +++ b/doc/cx16.sgml @@ -243,6 +243,12 @@ point to

+ + + This driver features a resolution of 640 across and 480 down with 2 colors, + black and white. +

+ Extended memory drivers

From d24a8d7e61623089e54c1a18c1b73a0dac4eeeae Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 21:09:02 -0500 Subject: [PATCH 05/22] fixed newline --- libsrc/cx16/tgi/cx640p1.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 110edba4a..4d6e267a1 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -633,4 +633,4 @@ CALC: rts -.include "../../tgi/tgidrv_line.inc" \ No newline at end of file +.include "../../tgi/tgidrv_line.inc" From b7f4c1746030c046b819231aab8cfffa072373f3 Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 21:23:50 -0500 Subject: [PATCH 06/22] dangling spaces --- libsrc/cx16/tgi/cx640p1.s | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 4d6e267a1..5fc05c22e 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -2,7 +2,7 @@ ; Graphics driver for the 640 pixels across, 480 pixels down, 2 color mode ; on the Commander X16 ; -; 2024-06-11, Scott Hutter +; 2024-06-11, Scott Hutter ; Based on code by Greg King ; @@ -239,7 +239,7 @@ CONTROL: ; ; Must set an error code: NO -CLEAR : +CLEAR: .scope inner ; set up DCSEL=2 @@ -273,13 +273,13 @@ ahead: ldy #240 ; number of rows blank_outer: - ldx #10 ; 10 iterations of 32 = one line of 320 at 8bpp + ldx #10 ; 10 iterations of 32 = one line of 640 blank_loop: - .repeat 8 + .repeat 8 stz VERA::DATA0 ; $9f23 each `stz` writes four zeroes to VRAM (cache contents) for a total of 32 pixels when repeated 8x .endrep - + dex bne blank_loop dey @@ -295,7 +295,7 @@ blank_loop: .endscope rts - + ; ------------------------------------------------------------------------ ; SETVIEWPAGE: Set the visible page. Called with the new page in .A (0..n-1). From 0837f9c25f20c7bf3376dba255145a6e9cf18b46 Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 21:29:37 -0500 Subject: [PATCH 07/22] spaces --- libsrc/cx16/tgi/cx640p1.s | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 5fc05c22e..4f806677c 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -394,7 +394,7 @@ SETPIXEL: stx VERA::ADDR + 2 ldx TEMP - + lda BITMASK beq @ahead @@ -402,7 +402,6 @@ SETPIXEL: ; Set the bit in the byte at VERA_DATA0 lda VERA::DATA0 ; Load the byte at memory address ora bitMasks1,X ; OR with the bit mask - ;lda 0 sta VERA::DATA0 ; Store back the modified byte rts @@ -441,7 +440,7 @@ GETPIXEL: lda #$00 rts - @ahead: + @ahead: ldx #$00 lda #$01 rts From 60f9081ea4e5bad7adac0571e61a194b557837ca Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 21:40:51 -0500 Subject: [PATCH 08/22] some comment alignment --- libsrc/cx16/tgi/cx640p1.s | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 4f806677c..9af091c9b 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -113,20 +113,20 @@ CURRENT_X: ; VERA's palette. Vera's palette is a table of Red, Green, and Blue levels. ; The first 16 RGB elements mimic the Commodore 64's colors. -SCRBASE: .res 1 ; High byte of screen base -BITMASK: .res 1 ; $00 = clear, $FF = set pixels -OLDCOLOR: .res 1 ; colors before entering gfx mode +SCRBASE: .res 1 ; High byte of screen base +BITMASK: .res 1 ; $00 = clear, $FF = set pixels +OLDCOLOR: .res 1 ; colors before entering gfx mode defpalette: .res $0100 palette: .res $0100 -bcolor := palette + 0 ; Background color -color: .res 1 ; Stroke and fill index -text_mode: .res 1 ; Old text mode +bcolor := palette + 0 ; Background color +color: .res 1 ; Stroke and fill index +text_mode: .res 1 ; Old text mode .data -error: .byte TGI_ERR_OK ; Error code +error: .byte TGI_ERR_OK ; Error code ; Constants and tables @@ -193,13 +193,13 @@ INIT: stz error ; #TGI_ERR_OK ; Switch into (640 x 480 x 2) graphics mode. - lda #%00000000 ; DCSEL = 0, VRAM port 1 + lda #%00000000 ; DCSEL = 0, VRAM port 1 sta VERA::CTRL - lda #%00100001 ; Disable sprites, layer 1 enable, VGA + lda #%00100001 ; Disable sprites, layer 1 enable, VGA sta VERA::DISP::VIDEO - lda #%00000100 ; Bitmap mode enable + lda #%00000100 ; Bitmap mode enable sta VERA::L1::CONFIG - lda #%00000001 ; Tile width 640 + lda #%00000001 ; Tile width 640 sta VERA::L1::TILE_BASE rts @@ -248,7 +248,7 @@ CLEAR: ; set cache writes lda #$40 - tsb $9f29 ;VERA_FX_CTRL + tsb $9F29 ;VERA_FX_CTRL ; set FX cache to all zeroes lda #(6 << 1) @@ -260,24 +260,24 @@ CLEAR: lda #$ff ahead: sta VERA::DISP::VIDEO - sta VERA::DISP::HSCALE ;$9f2a - sta VERA::DISP::VSCALE ;$9f2b - sta VERA::DISP::FRAME ;$9f2c + sta VERA::DISP::HSCALE + sta VERA::DISP::VSCALE + sta VERA::DISP::FRAME stz VERA::CTRL ; set address and increment for bitmap area stz VERA::ADDR stz VERA::ADDR + 1 - lda #$30 ; increment +4 + lda #$30 ; increment +4 sta VERA::ADDR + 2 - ldy #240 ; number of rows + ldy #$F0 blank_outer: - ldx #10 ; 10 iterations of 32 = one line of 640 + ldx #$0A blank_loop: .repeat 8 - stz VERA::DATA0 ; $9f23 each `stz` writes four zeroes to VRAM (cache contents) for a total of 32 pixels when repeated 8x + stz VERA::DATA0 .endrep dex @@ -287,10 +287,10 @@ blank_loop: ; set up DCSEL=2 lda #(2 << 1) - sta VERA::CTRL ; $9f25 + sta VERA::CTRL ; set FX off (cache write bit 1 -> 0) - stz $9f29 ;VERA_FX_CTRL + stz $9F29 ;VERA_FX_CTRL stz VERA::CTRL .endscope From 550f94b773d8561589229d10d71f86ea3cf2c25a Mon Sep 17 00:00:00 2001 From: xlar54 Date: Thu, 13 Jun 2024 23:13:05 -0500 Subject: [PATCH 09/22] make setpalette return error --- libsrc/cx16/tgi/cx640p1.s | 64 ++++++++++++++------------------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 9af091c9b..12b732613 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -84,27 +84,7 @@ TEMP = tmp3 TEMP2 = tmp4 ; HORLINE TEMP3 = sreg ; HORLINE -tempX: -.byte $00, $00 -tempY: -.byte $00, $00 -ERR2: -.byte $00 -ERR: -.byte $00 -SY: -.byte $00 -SX: -.byte $00 -DY: -.byte $00 -DX: -.byte $00 -CURRENT_Y: -.byte $00, $00 -CURRENT_X: -.byte $00, $00 ; Absolute variables used in the code .bss @@ -124,9 +104,20 @@ bcolor := palette + 0 ; Background color color: .res 1 ; Stroke and fill index text_mode: .res 1 ; Old text mode +tempX: .res 2 +tempY: .res 2 +ERR2: .res 1 +ERR: .res 1 +SY: .res 1 +SX: .res 1 +DY: .res 1 +DX: .res 1 +CURRENT_Y: .res 2 +CURRENT_X: .res 2 + .data -error: .byte TGI_ERR_OK ; Error code +ERROR: .byte TGI_ERR_OK ; Error code ; Constants and tables @@ -183,7 +174,7 @@ UNINSTALL: ; ; Must set an error code: YES -INIT: stz error ; #TGI_ERR_OK +INIT: stz ERROR ; #TGI_ERR_OK ; Save the current text mode. @@ -220,8 +211,8 @@ DONE: ; GETERROR: Return the error code in .A, and clear it. GETERROR: - lda error - stz error + lda ERROR + stz ERROR rts ; ------------------------------------------------------------------------ @@ -231,7 +222,7 @@ GETERROR: CONTROL: lda #TGI_ERR_INV_FUNC - sta error + sta ERROR rts ; ------------------------------------------------------------------------ @@ -254,10 +245,8 @@ CLEAR: lda #(6 << 1) sta VERA::CTRL - lda #$00 ; color - ; $00=black, $01=white - beq ahead - lda #$ff + lda #$00 + ahead: sta VERA::DISP::VIDEO sta VERA::DISP::HSCALE @@ -324,16 +313,9 @@ SETDRAWPAGE: ; Must set an error code: YES SETPALETTE: - stz error ; #TGI_ERR_OK - ldy #$00 -: lda (ptr1),y - sta palette,y - iny - bnz :- - - lda color ; Get stroke and fill index - - ; Fall through. + lda #TGI_ERR_INV_FUNC + sta ERROR + rts ; ------------------------------------------------------------------------ ; SETCOLOR: Set the drawing color (in .A). The new color already is checked @@ -398,7 +380,7 @@ SETPIXEL: lda BITMASK beq @ahead - ; if COLOR = 1, white is line color + ; if BITMASK = $00, white is line color ; Set the bit in the byte at VERA_DATA0 lda VERA::DATA0 ; Load the byte at memory address ora bitMasks1,X ; OR with the bit mask @@ -406,7 +388,7 @@ SETPIXEL: rts @ahead: - ; if COLOR = 0, black is line color + ; if BITMASK = $FF, black is line color lda VERA::DATA0 ; Load the byte at memory address and bitMasks2,X ; OR with the bit mask sta VERA::DATA0 ; Store back the modified byte From 5caed9a15f14c00a920f0ac7c08b8dc41118a7c6 Mon Sep 17 00:00:00 2001 From: xlar54 Date: Sun, 16 Jun 2024 14:46:00 -0500 Subject: [PATCH 10/22] fixed setpalette --- libsrc/cx16/tgi/cx640p1.s | 87 ++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 12b732613..9a154dfcf 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -31,7 +31,7 @@ .addr $0000 ; Library reference .word 640 ; X resolution .word 480 ; Y resolution - .byte 2 ; Number of drawing colors + .byte 2 ; Number of drawing colors .byte 0 ; Number of screens available .byte 8 ; System font X size .byte 8 ; System font Y size @@ -95,12 +95,9 @@ TEMP3 = sreg ; HORLINE SCRBASE: .res 1 ; High byte of screen base BITMASK: .res 1 ; $00 = clear, $FF = set pixels -OLDCOLOR: .res 1 ; colors before entering gfx mode -defpalette: .res $0100 -palette: .res $0100 +palette: .res 2 -bcolor := palette + 0 ; Background color color: .res 1 ; Stroke and fill index text_mode: .res 1 ; Old text mode @@ -124,6 +121,24 @@ ERROR: .byte TGI_ERR_OK ; Error code .rodata +defpalette: +col_black: .byte %00000000, %00000000 +col_white: .byte %11111111, %00001111 +col_red: .byte %00000000, %00001000 +col_cyan: .byte %11111110, %00001010 +col_purple: .byte %01001100, %00001100 +col_green: .byte %11000101, %00000000 +col_blue: .byte %00001010, %00000000 +col_yellow: .byte %11100111, %00001110 +col_orange: .byte %10000101, %00001101 +col_brown: .byte %01000000, %00000110 +col_lred: .byte %01110111, %00001111 +col_gray1: .byte %00110011, %00000011 +col_gray2: .byte %01110111, %00000111 +col_lgreen: .byte %11110110, %00001010 +col_lblue: .byte %10001111, %00000000 +col_gray3: .byte %10111011, %00001011 + ; Bit masks for setting pixels bitMasks1: .byte %10000000, %01000000, %00100000, %00010000 @@ -144,12 +159,10 @@ bitMasks2: INSTALL: ; Create the default palette. - - ldx #$00 -: txa - sta defpalette,x - inx - bnz :- + lda #$00 + sta palette + lda #$01 + sta palette+1 ; Fall through. @@ -182,7 +195,7 @@ INIT: stz ERROR ; #TGI_ERR_OK jsr SCREEN_MODE sta text_mode -; Switch into (640 x 480 x 2) graphics mode. +; Switch into (640 x 480 x 2 bpp) graphics mode. lda #%00000000 ; DCSEL = 0, VRAM port 1 sta VERA::CTRL @@ -313,8 +326,53 @@ SETDRAWPAGE: ; Must set an error code: YES SETPALETTE: - lda #TGI_ERR_INV_FUNC - sta ERROR + stz ERROR ; #TGI_ERR_OK + ldy #$01 ; Palette size of 2 colors +@L1: lda (ptr1),y ; Copy the palette + sta palette,y + dey + bpl @L1 + + ; set background color from palette color 0 + lda #$00 + sta VERA::ADDR + lda #$FA + sta VERA::ADDR+1 + lda #$01 + sta VERA::ADDR+2 ; write color RAM @ $1FA00 + + lda palette + asl + tay + lda defpalette,y + sta VERA::DATA0 + + inc VERA::ADDR ; $1FA01 + + lda palette + asl + tay + iny ; second byte of color + lda defpalette,y + sta VERA::DATA0 + + ; set foreground color from palette color 1 + inc VERA::ADDR ; $1FA02 + + lda palette+1 + asl + tay + lda defpalette,y + sta VERA::DATA0 + + inc VERA::ADDR ; $1FA03 + + lda palette+1 + asl + tay + iny ; second byte of color + lda defpalette,y + sta VERA::DATA0 rts ; ------------------------------------------------------------------------ @@ -328,6 +386,7 @@ SETCOLOR: beq @L1 lda #$FF @L1: sta BITMASK + stx color rts ; ------------------------------------------------------------------------ From 6dbf5f528ac4f4b8bb2692c156d039f98fa4860f Mon Sep 17 00:00:00 2001 From: xlar54 Date: Sun, 16 Jun 2024 14:51:53 -0500 Subject: [PATCH 11/22] argh dangling spaces --- libsrc/cx16/tgi/cx640p1.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 9a154dfcf..dde4024e5 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -361,7 +361,7 @@ SETPALETTE: lda palette+1 asl - tay + tay lda defpalette,y sta VERA::DATA0 From 6098ac278821d290b58a966f881de1d94a21534b Mon Sep 17 00:00:00 2001 From: xlar54 Date: Sun, 16 Jun 2024 16:06:38 -0500 Subject: [PATCH 12/22] fix for getdefpalette --- libsrc/cx16/tgi/cx640p1.s | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index dde4024e5..034bbb086 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -96,6 +96,7 @@ TEMP3 = sreg ; HORLINE SCRBASE: .res 1 ; High byte of screen base BITMASK: .res 1 ; $00 = clear, $FF = set pixels +defpalette: .res 2 palette: .res 2 color: .res 1 ; Stroke and fill index @@ -121,7 +122,7 @@ ERROR: .byte TGI_ERR_OK ; Error code .rodata -defpalette: +veracolors: col_black: .byte %00000000, %00000000 col_white: .byte %11111111, %00001111 col_red: .byte %00000000, %00001000 @@ -160,9 +161,9 @@ bitMasks2: INSTALL: ; Create the default palette. lda #$00 - sta palette + sta defpalette lda #$01 - sta palette+1 + sta defpalette+1 ; Fall through. @@ -344,7 +345,7 @@ SETPALETTE: lda palette asl tay - lda defpalette,y + lda veracolors,y sta VERA::DATA0 inc VERA::ADDR ; $1FA01 @@ -353,7 +354,7 @@ SETPALETTE: asl tay iny ; second byte of color - lda defpalette,y + lda veracolors,y sta VERA::DATA0 ; set foreground color from palette color 1 @@ -362,7 +363,7 @@ SETPALETTE: lda palette+1 asl tay - lda defpalette,y + lda veracolors,y sta VERA::DATA0 inc VERA::ADDR ; $1FA03 @@ -371,7 +372,7 @@ SETPALETTE: asl tay iny ; second byte of color - lda defpalette,y + lda veracolors,y sta VERA::DATA0 rts From 3b494ad6f2353e0aa9bc142af47371e406fb449b Mon Sep 17 00:00:00 2001 From: xlar54 Date: Wed, 19 Jun 2024 23:50:54 -0500 Subject: [PATCH 13/22] alignment fixes --- libsrc/cx16/tgi/cx640p1.s | 104 +++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 034bbb086..93d5cb698 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -31,7 +31,7 @@ .addr $0000 ; Library reference .word 640 ; X resolution .word 480 ; Y resolution - .byte 2 ; Number of drawing colors + .byte 2 ; Number of drawing colors .byte 0 ; Number of screens available .byte 8 ; System font X size .byte 8 ; System font Y size @@ -198,14 +198,14 @@ INIT: stz ERROR ; #TGI_ERR_OK ; Switch into (640 x 480 x 2 bpp) graphics mode. - lda #%00000000 ; DCSEL = 0, VRAM port 1 - sta VERA::CTRL - lda #%00100001 ; Disable sprites, layer 1 enable, VGA - sta VERA::DISP::VIDEO - lda #%00000100 ; Bitmap mode enable - sta VERA::L1::CONFIG - lda #%00000001 ; Tile width 640 - sta VERA::L1::TILE_BASE + lda #%00000000 ; DCSEL = 0, VRAM port 1 + sta VERA::CTRL + lda #%00100001 ; Disable sprites, layer 1 enable, VGA + sta VERA::DISP::VIDEO + lda #%00000100 ; Bitmap mode enable + sta VERA::L1::CONFIG + lda #%00000001 ; Tile width 640 + sta VERA::L1::TILE_BASE rts ; ------------------------------------------------------------------------ @@ -245,59 +245,57 @@ CONTROL: ; Must set an error code: NO CLEAR: - .scope inner + .scope inner - ; set up DCSEL=2 - lda #(2 << 1) - sta VERA::CTRL + ; set up DCSEL=2 + lda #(2 << 1) + sta VERA::CTRL - ; set cache writes - lda #$40 - tsb $9F29 ;VERA_FX_CTRL + ; set cache writes + lda #$40 + tsb VERA::DISP::VIDEO ; VERA_FX_CTRL when DCSEL=2 - ; set FX cache to all zeroes - lda #(6 << 1) - sta VERA::CTRL + ; set FX cache to all zeroes + lda #(6 << 1) + sta VERA::CTRL - lda #$00 + lda #$00 + sta VERA::DISP::VIDEO + sta VERA::DISP::HSCALE + sta VERA::DISP::VSCALE + sta VERA::DISP::FRAME -ahead: - sta VERA::DISP::VIDEO - sta VERA::DISP::HSCALE - sta VERA::DISP::VSCALE - sta VERA::DISP::FRAME + stz VERA::CTRL + ; set address and increment for bitmap area + stz VERA::ADDR + stz VERA::ADDR + 1 + lda #$30 ; increment +4 + sta VERA::ADDR + 2 - stz VERA::CTRL - ; set address and increment for bitmap area - stz VERA::ADDR - stz VERA::ADDR + 1 - lda #$30 ; increment +4 - sta VERA::ADDR + 2 + ldy #$F0 +@blank_outer: + ldx #$0A +@blank_loop: - ldy #$F0 -blank_outer: - ldx #$0A -blank_loop: + .repeat 8 + stz VERA::DATA0 + .endrep - .repeat 8 - stz VERA::DATA0 - .endrep + dex + bne @blank_loop + dey + bne @blank_outer - dex - bne blank_loop - dey - bne blank_outer + ; set up DCSEL=2 + lda #(2 << 1) + sta VERA::CTRL - ; set up DCSEL=2 - lda #(2 << 1) - sta VERA::CTRL + ; set FX off (cache write bit 1 -> 0) + stz $9F29 ;VERA_FX_CTRL + stz VERA::CTRL - ; set FX off (cache write bit 1 -> 0) - stz $9F29 ;VERA_FX_CTRL - stz VERA::CTRL - - .endscope - rts + .endscope + rts ; ------------------------------------------------------------------------ @@ -447,7 +445,7 @@ SETPIXEL: sta VERA::DATA0 ; Store back the modified byte rts - @ahead: +@ahead: ; if BITMASK = $FF, black is line color lda VERA::DATA0 ; Load the byte at memory address and bitMasks2,X ; OR with the bit mask @@ -482,7 +480,7 @@ GETPIXEL: lda #$00 rts - @ahead: +@ahead: ldx #$00 lda #$01 rts From 3d5fd0489e131106044c34f51efb32929092cc81 Mon Sep 17 00:00:00 2001 From: xlar54 Date: Wed, 19 Jun 2024 23:52:25 -0500 Subject: [PATCH 14/22] replaced constant --- libsrc/cx16/tgi/cx640p1.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cx16/tgi/cx640p1.s b/libsrc/cx16/tgi/cx640p1.s index 93d5cb698..287160f6b 100644 --- a/libsrc/cx16/tgi/cx640p1.s +++ b/libsrc/cx16/tgi/cx640p1.s @@ -291,7 +291,7 @@ CLEAR: sta VERA::CTRL ; set FX off (cache write bit 1 -> 0) - stz $9F29 ;VERA_FX_CTRL + stz VERA::DISP::VIDEO ; VERA_FX_CTRL when DCSEL=2 stz VERA::CTRL .endscope From 871bafa5b33ca8a13b891f8cd66b282ae8d90cc9 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 7 Jul 2024 00:48:15 +0200 Subject: [PATCH 15/22] Keep gcc-14 from aborting with errors due to new defaults. Adds -Wno-error=implicit-int -Wno-error=int-conversion to CFLAGS. Tested with gcc-12.4 and gcc-14.1. --- test/ref/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ref/Makefile b/test/ref/Makefile index 5c189c6cb..e82c6de37 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -50,7 +50,7 @@ ISEQUAL = ..$S..$Stestwrk$Sisequal$(EXE) # will have to change that, and create said special cases here. # see discussion in https://github.com/cc65/cc65/issues/2277 CC = gcc -CFLAGS = -std=gnu17 -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow +CFLAGS = -std=gnu17 -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow -Wno-error=implicit-int -Wno-error=int-conversion .PHONY: all clean From cdb2d49e3a5737c4b4d2ad33bc512aaa4e8aec2a Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 7 Jul 2024 01:02:32 +0200 Subject: [PATCH 16/22] Test strtok(). --- test/ref/strtok.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/ref/strtok.c diff --git a/test/ref/strtok.c b/test/ref/strtok.c new file mode 100644 index 000000000..15c3a289d --- /dev/null +++ b/test/ref/strtok.c @@ -0,0 +1,43 @@ +// 2024-02-14 Sven Michael Klose + +#include +#include +#include + +void +error (void) +{ + printf ("strtok() test failed!\n"); + exit (-1); +} + +void +test (char * s) +{ + if (strcmp ("test", strtok (s, "/"))) + error (); + if (strcmp ("foo", strtok (NULL, "/"))) + error (); + if (strcmp ("bar", strtok (NULL, "/"))) + error (); + if (strtok (NULL, "/")) + error (); + if (strtok (NULL, "/")) + error (); +} + +int +main (void) +{ + char s1[] = "test/foo/bar"; + char s2[] = "/test/foo/bar"; + char s3[] = "//test/foo/bar"; + char s4[] = "//test/foo/bar//"; + + test (s1); + test (s2); + test (s3); + test (s4); + + return 0; +} From 581b79e0b9097592ab32bb00edce33c06d72917b Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 7 Jul 2024 14:04:49 +0200 Subject: [PATCH 17/22] Add stpcpy(). Like strcpy() but returning pointer to ending zero of copied string. --- include/string.h | 1 + libsrc/common/stpcpy.c | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 libsrc/common/stpcpy.c diff --git a/include/string.h b/include/string.h index b19f44e31..06c97d464 100644 --- a/include/string.h +++ b/include/string.h @@ -52,6 +52,7 @@ char* __fastcall__ strchr (const char* s, int c); int __fastcall__ strcmp (const char* s1, const char* s2); int __fastcall__ strcoll (const char* s1, const char* s2); char* __fastcall__ strcpy (char* dest, const char* src); +char* __fastcall__ stpcpy (char* dest, const char* src); size_t __fastcall__ strcspn (const char* s1, const char* s2); char* __fastcall__ strerror (int errcode); size_t __fastcall__ strlen (const char* s); diff --git a/libsrc/common/stpcpy.c b/libsrc/common/stpcpy.c new file mode 100644 index 000000000..153a3e361 --- /dev/null +++ b/libsrc/common/stpcpy.c @@ -0,0 +1,8 @@ +#include + +char * __fastcall__ +stpcpy (char * dst, const char * src) +{ + strcpy (dst, src); + return dst + strlen (src); +} From af3ac423733637c74400818d5281b3d3ec643df4 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 7 Jul 2024 19:48:44 +0200 Subject: [PATCH 18/22] Move stpcpy() to non-standard section. --- include/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/string.h b/include/string.h index 06c97d464..3b7ece1d9 100644 --- a/include/string.h +++ b/include/string.h @@ -52,7 +52,6 @@ char* __fastcall__ strchr (const char* s, int c); int __fastcall__ strcmp (const char* s1, const char* s2); int __fastcall__ strcoll (const char* s1, const char* s2); char* __fastcall__ strcpy (char* dest, const char* src); -char* __fastcall__ stpcpy (char* dest, const char* src); size_t __fastcall__ strcspn (const char* s1, const char* s2); char* __fastcall__ strerror (int errcode); size_t __fastcall__ strlen (const char* s); @@ -91,6 +90,7 @@ char* __fastcall__ strlower (char* s); char* __fastcall__ strupr (char* s); char* __fastcall__ strupper (char* s); char* __fastcall__ strqtok (char* s1, const char* s2); +char* __fastcall__ stpcpy (char* dest, const char* src); #endif const char* __fastcall__ __stroserror (unsigned char errcode); From 816bcabe5aeb2b1dd3d884f2f1a091599b41a536 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 14 Jul 2024 23:12:59 +0200 Subject: [PATCH 19/22] Move strtok() test to correct section. --- test/{ref => val}/strtok.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{ref => val}/strtok.c (100%) diff --git a/test/ref/strtok.c b/test/val/strtok.c similarity index 100% rename from test/ref/strtok.c rename to test/val/strtok.c From 9558ebad624ed7c03eb7ddee12445482d1749a19 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Mon, 15 Jul 2024 17:35:28 +0200 Subject: [PATCH 20/22] Add test for stpcpy(). --- test/val/stpcpy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/val/stpcpy.c diff --git a/test/val/stpcpy.c b/test/val/stpcpy.c new file mode 100644 index 000000000..8bdbfb926 --- /dev/null +++ b/test/val/stpcpy.c @@ -0,0 +1,44 @@ +// 2024-07-15 Sven Michael Klose + +#include +#include +#include +#include + +#define STR_SHORT "Hello, World!" +#define STR_LONG "This is a longer test string for stpcpy." + +int +main () +{ + char dest[50]; + const char *src_empty; + const char *src_short; + const char *src_long; + char *end; + + src_empty = ""; + end = stpcpy (dest, src_empty); + assert(!strcmp (dest, src_empty)); + assert(!*end); + assert(end == dest); + printf ("Test 1 passed.\n"); + + src_short = STR_SHORT; + end = stpcpy (dest, src_short); + assert(!strcmp (dest, src_short)); + assert(!*end); + assert(end == &dest[sizeof (STR_SHORT) - 1]); + printf ("Test 2 passed.\n"); + + src_long = STR_LONG; + end = stpcpy (dest, src_long); + assert(!strcmp (dest, src_long)); + assert(!*end); + assert(end == &dest[sizeof (STR_LONG) - 1]); + printf ("Test 3 passed.\n"); + + printf ("All tests passed.\n"); + return EXIT_SUCCESS; +} + From 677cd8ff4e2cd699375498baa93487fc756a43e6 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Mon, 15 Jul 2024 17:54:43 +0200 Subject: [PATCH 21/22] Use standard library's exit() code constants. --- test/val/strtok.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/val/strtok.c b/test/val/strtok.c index 15c3a289d..4d63bfb2a 100644 --- a/test/val/strtok.c +++ b/test/val/strtok.c @@ -1,5 +1,3 @@ -// 2024-02-14 Sven Michael Klose - #include #include #include @@ -8,7 +6,7 @@ void error (void) { printf ("strtok() test failed!\n"); - exit (-1); + exit (EXIT_FAILURE); } void @@ -39,5 +37,5 @@ main (void) test (s3); test (s4); - return 0; + return EXIT_SUCCESS; } From aed94d2dae9755a77040fec396d84edc883892ef Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Tue, 16 Jul 2024 01:33:48 +0200 Subject: [PATCH 22/22] Fix code style. Have type, function name and argument declaration on a single line. --- libsrc/common/stpcpy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsrc/common/stpcpy.c b/libsrc/common/stpcpy.c index 153a3e361..12af47f2f 100644 --- a/libsrc/common/stpcpy.c +++ b/libsrc/common/stpcpy.c @@ -1,7 +1,6 @@ #include -char * __fastcall__ -stpcpy (char * dst, const char * src) +char * __fastcall__ stpcpy (char * dst, const char * src) { strcpy (dst, src); return dst + strlen (src);