Jump to content
IGNORED

The "funkheld" Question Thread


funkheld

Recommended Posts

Hi!

 

hello, good day.

 

shifts in fastbasic, how does that work?

Shift left is easy, simply multiply by 2. The optimizer recognizes the sequence " X * 2 " and converts it to "ShiftLeft X".

 

Shift right is not easy, as integer division only works if the number is positive.

 

What do you need to do? Perhaps it can be written in a form that does not need shifts.

  • Like 1
Link to comment
Share on other sites

Hi!

 

can you do anything with usr and asm?

 

greeting

Oh, yes, you can implement anything with USR ;)

 

' Create shift left routines.

' Define a Machine Language routine:
'                     PLA/LSR/TAX/PLA/ROR/RTS
data lsr_asm() byte = $68,$4a,$aa,$68,$6a,$60
'                     PLA/TAX/PLA/TXA/LDX #0 /RTS
data lsr8_asm() byte =$68,$aa,$68,$8a,$a2,$00,$60

' Calls the routine with different values
for i=0 to 2000 step 100
    ? i, usr(adr(lsr_asm),i), usr(adr(lsr8_asm),i)
next i
  • Like 2
Link to comment
Share on other sites

Thanks for help.

 

I also wanted to do an LSL:

' PLA/CLC/ROL/TAX/PLA/ROL/RTS
data lsl_asm() byte = $68,$18,$2a,$aa,$68,$2a,$60
I do not get an integer as a result.
why not?
this is ok:
' PLA/LSR/TAX/PLA/ROR/RTS
data lsr_asm() byte = $68,$4a,$aa,$68,$6a,$60
greeting
 
'                     PLA/LSR/TAX/PLA/ROR/RTS
data lsr_asm() byte = $68,$4a,$aa,$68,$6a,$60
 
'                     PLA/CLC/ROL/TAX/PLA/ROL/RTS
data lsl_asm() byte = $68,$18,$2a,$aa,$68,$2a,$60
 
z=0
i=8197
print i
 
for y=0 to 12
  z=usr(adr(lsr_asm),i)
  print z
  i=z
next y
 
? "-----------------------"
 
for y=0 to 12
  z=usr(adr(lsl_asm),i)
  print z
  i=z
next y
 
repeat 
until key()
greeting

post-31221-0-81382300-1537699952.jpg

Edited by funkheld
Link to comment
Share on other sites

Hi!

 

Thanks for help.

 

I also wanted to do an LSL:

' PLA/CLC/ROL/TAX/PLA/ROL/RTS

data lsl_asm() byte = $68,$18,$2a,$aa,$68,$2a,$60

 

 

I do not get an integer as a result.

why not?

As I said before, in FastBasic it is faster to simply use "I*2", that will be optimized to la left shift.

 

As to why your ASM routine does not work, it is because in assembler, to do a left shift, you need to shift the LOW part first, then the HIGH part (it is the same as multiplying or adding in decimal, you start with the rightmost digit).

A proper ASM routine would be:

; Get 16 bit value from the stack to AX
        pla
        tax
        pla
; Shift left, first "A", then "X" (storing A into Y temporarily)
        asl
        tay
        txa
        rol
        tax
        tya
; Returns
        rts
You can see the way FastBasic does it in the source: https://github.com/dmsc/fastbasic/blob/master/src/interp/ushl.asm#L35

 

But I repeat: a left-shift is exactly the same as multiplying by 2.

  • Like 1
Link to comment
Share on other sites



good evening.


have now installed the lsr and lsl in a proc.

a wonderful thing you did with fastbasic.


Thank you.




.global LSL
.global LSR

.proc LSL
pla
tax
pla
asl
tay
txa
rol
tax
tya
rts
.endproc

.proc LSR
pla
lsr
tax
pla
ror
rts
.endproc




a = 2
for z=0 to 7
a = usr(@lsl, a)
? a
next z

? "-------------------"

a = 1024
for z=0 to 7
a= usr(@lsr, a)
? a
next z

repeat
until key()

end




Edited by funkheld
Link to comment
Share on other sites

I also use other start addresses: $ 3200 ... $ 3000 etc ...

 

thanks for the help.

 

fb.bat -S:0x2000 mygame.bas... this is very good.

 

-------------------------------

Yes, but only in the development versions (the one I posted before),

-------------------------------

can you please put her in here?

thanks.

 

greeting

Edited by funkheld
Link to comment
Share on other sites

Hi!

 

I also use other start addresses: $ 3200 ... $ 3000 etc ...

 

thanks for the help.

 

fb.bat -S:0x2000 mygame.bas... this is very good.

 

-------------------------------

Yes, but only in the development versions (the one I posted before),

-------------------------------

can you please put her in here?

thanks.

 

greeting

I posted it here: http://atariage.com/forums/topic/283102-how-can-you-use-fastbasic-a-hex-print-hex-54000/?p=4116728

Link to comment
Share on other sites

Hi good afternoon.
what is missing here please, that I can start this miniprogram?
it is not compiled.
I would like to practice with individual sharing.
Thank you.
greeting

 

procedure InitGraph(mode: byte); 
 
var window: byte;
begin
 
GraphResult := 0;
 
window := mode and $10;
 
ScreenMode := mode;
 
mode := mode and $0f;
 
ScreenHeight := 192;
 
case mode of
0,3: begin ScreenWidth := 40; ScreenHeight := 24 end;
5: begin ScreenWidth := 80; ScreenHeight := 48 end;
6..7: begin ScreenWidth := 160; ScreenHeight := 96 end;
8: ScreenWidth := 320;
9..11: ScreenWidth := 80;
15: ScreenWidth := 160
 
else
GraphResult := 128;
end;
 
asm
{ txa:pha
 
mva #$2c @putchar.vbxe
 
ldy mode
 
ldx #$60 ; 6*16
lda window ; %00010000 with text window
eor #$10
ora #2 ; read
 
.nowarn @graphics
 
pla:tax
};
end;
 
procedure MoveTo(x, y: smallint); assembler;
//----------------------------------------------------------------------------------------------
// Move cursor to absolute position
//----------------------------------------------------------------------------------------------
asm
{ lda y+1
bpl _0
 
lda #0
sta y
sta y+1
_0
lda x+1
bpl _1
 
lda #0
sta x
sta x+1
_1
cpw y main.system.ScreenHeight
bcc _2
 
sbw main.system.ScreenHeight #1 y
_2
cpw x main.system.ScreenWidth
bcc _3
 
sbw main.system.ScreenWidth #1 x
_3
mwa x CurrentX
mwa y CurrentY
};
end;
 
procedure LineTo(x, y: smallint); assembler;
(*
@description:
Draw a line starting from current position to a given point
*)
asm
{ lda y+1
bpl _0
 
lda #0
sta y
sta y+1
_0
lda x+1
bpl _1
 
lda #0
sta x
sta x+1
_1
cpw y main.system.ScreenHeight
bcc _2
 
sbw main.system.ScreenHeight #1 y
_2
cpw x main.system.ScreenWidth
bcc _3
 
sbw main.system.ScreenWidth #1 x
_3
txa:pha
 
mwa CurrentX colcrs
mva CurrentY rowcrs
 
lda #@IDput
 
jsr @COMMAND
 
lda x
sta colcrs
sta CurrentX
lda x+1
sta colcrs+1
sta CurrentX+1
 
mva y rowcrs
sta CurrentY
lda y+1
sta CurrentY+1
 
lda #@IDdraw
 
jsr @COMMAND
 
pla:tax
};
end;
 
begin
  InitGraph(;
  MoveTo(10,10);
  LineTo(100,100);
  
  repeat until keypressed;  
end.
Edited by funkheld
Link to comment
Share on other sites

Hi good afternoon.


how can you please a picture from screen 23 read?



this is to screen 23 write :



uses crt, graph;

var
f : file;
s : string[15];
buf: ^byte;

begin
InitGraph(23);
s := 'D:MULBI.BIN';

assign(f, s);
reset(f, 1);

buf:=pointer(dpeek(88));

blockread(f, buf, 3840);

buf:=pointer(712);
blockread(f, buf, 1);

buf:=pointer(708);
blockread(f, buf, 3);

close(f);

repeat until keypressed;
end.


Link to comment
Share on other sites

hello, good day.
I have a demo from a dli.
that gives an error.
where is the error please?
Thank you.
greeting

 

 

uses crt, graph;
 
var
  dlist : word;
 
procedure DLI_routine;
begin
  asm
  {  
  stx @sp
    
  lda #<dli  ; Set up our display list interrupt vector
  sta $200
  lda #>dli
  sta $201
  lda #$c0   ; Enable DLI + Vertical blank routines
  sta nmien
  };
  
  gotoxy(8, 16); writeln('Some more text...');  
  
  asm
  {
loop
  jmp loop    ; Wait forever     
        
dli
  pha         ; Save registers
  lda #0      ; New text color
  ldx #36     ; New background color
  stx WSYNC   ; Wait 
  sta COLPF1  ; Store color
  stx COLPF2  ; Store color
  pla         ; Restore registers
  rti         ; Done
 
  ldx @sp
  };  
end;
  
begin
  InitGraph(0); CursorOff;
  dlist := DPeek($230);
  Poke(dlist+16, 130);
  gotoxy(6, 5); writeln('Display list interrupt example');
  DLI_routine;
  gotoxy(8, 20); writeln('Is this text shown?');    
 repeat
 until keypressed;
end.

post-31221-0-12868300-1538565668.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...