Announcement

Collapse
No announcement yet.

24 bit numbers in memory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Buck Huffman
    replied
    Well, I fiddled around with it and this is what I've come up with
    so far. You were right Lance, it was walking on memory areas that
    were out of bounds.

    ' Set a Pixel.(Kinda Like PSet)
    SUB VesaPSet (x, y, BYVAL clr AS DWORD)
    DIM offset AS LOCAL DWORD
    DIM bank AS LOCAL WORD
    IF x > xRes OR y > yRes OR x < 0 OR y < 0 THEN EXIT SUB
    offset = (Bpsl * y) + (x * Bpp) + yOffset
    bank = (offset \ &H10000)
    offset = offset - &H10000 * bank
    IF curBank <> bank THEN
    ! mov ax, bank
    ! mul wingran
    ! mov dx, ax
    ! mov ax, &H4F05
    ! mov bx, &H0000
    ! call dword VidFunc
    curBank = bank ;this is way faster than !mov curBank, ax
    END IF
    ! mov ax, &HA000 ; move video segment
    ! mov es, ax ; into ES
    ! cld ; clear direction flag, thanks Lance
    ! mov di, offset ; pixel location into DI
    ! DB &H66 ;<-allows 32-bit regs in PB/DOS
    ! mov ax, clr ; color into EAX
    ! cmp offset, 65535 ; one byte left in bank
    ! jz disbyt
    ! stosw ; put low word to video mem first?
    ! cmp offset, 65534 ; two bytes left bank
    ! jb endme
    ! call nxtbnk ; bank switch routine
    endme:
    ! mov cl, 16 ; number of bits to shift
    ! DB &H66 ; 32-bit reg
    ! sar ax, cl ; shift the high word into position
    ! stosb ; send the stray byte to video
    ! jmp thatsall
    disbyt:
    ! stosb
    ! call nxtbnk
    ! mov cl, 8
    ! DB &H66
    ! sar ax, cl
    ! stosw
    ! jmp thatsall
    nxtbnk:
    ! mov ax, &H4F05
    ! mov bx, &H0000
    ! mov dx, curBank
    ! add dx, wingran
    ! mov curBank, dx
    ! call dword VidFunc ; switch to next bank
    ! mov ax, &HA000 ; re-load the regs
    ! mov es, ax
    ! cld
    ! mov di, 0
    ! DB &H66
    ! mov ax, clr
    ! retn
    thatsall:
    END SUB

    At least this one works, even though it's only a hair faster than
    the basic code, and I added some code to pick up the pixels that
    cross over bank boundries(that's what caused the memory address
    confusion, along with countless other problems). My asm skills are
    terrible. I'm just learning and it's slow going. If anyone out
    there can see any way to improve this code, I would most truely
    appreciate any help I could get. and if I ever get this thing
    working right, I'll try to post the code on this site somewhere.

    Thanks


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

    Leave a comment:


  • Lance Edmonds
    replied
    Oh, you might want to do a !CLD sometime before the !STOSB too, otherwise the expected DI increment could turn into a DI decrement.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    The nature of those critical errors suggests that your code is going outside the bounds and "stepping" on something it shouldn't outside of the VGA memory region.

    ASM is not really my bag, but the first thing is to do is to somehow log the ESI addresses to make sure the target pointer address is not going out of bounds... solve that and you most likely have your solution.

    Good luck!

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Buck Huffman
    started a topic 24 bit numbers in memory

    24 bit numbers in memory

    Does anybody know how to copy 24-bit numbers to the video memory
    in a reasonably fast manner in real mode.

    This code kinda works but if you call it too much it'll crash big
    time. Windows kicks my program out, and dos does a "SYSTEM HALTED!"

    ' Set a Pixel in vesa 24 bit mode.(Kinda Like PSet)
    SUB VesaPSet (x, y, BYVAL clr AS DWORD)
    DIM offset AS LOCAL DWORD
    DIM bank AS LOCAL WORD
    offset = (Bpsl * y) + (x * Bpp) + yOffset
    bank = (offset \ &H10000) ' * wingran
    offset = offset - &H10000 * bank
    bank = bank * wingran
    IF bank <> curBank THEN
    curBank = bank
    ! mov ax, &H4F05
    ! mov bx, &H0000
    ! mov dx, curBank
    ! call dword VidFunc
    END IF

    'everything before this is tested and works in the other modes.
    'so I'm sure the problem is in here somewhere.
    IF offset < 65535 THEN
    ! add offset, 2
    ! mov ax, &HA000
    ! mov di, offset
    ! mov es, ax
    ! mov ax, clr
    ! stosb
    ! mov cl, 8
    ! db &H66
    ! sar ax, cl
    ! sub offset, 2
    ! stosw
    END IF
    END SUB

    Can anyone see off hand where the error is, and could anyone help
    me to eliminate the backward memory write in a fast and clean way.
    Any help would be grately appreciated, this has been bugging me
    for days.

    All this trouble came from trying to convert this basic code to
    assembly.
    DEF SEG = &HA000
    IF offset& < 65535 THEN
    POKE offset&+2, BITS?(clr)
    SHIFT RIGHT clr, 8
    POKEI offset&, BITS??(clr)
    END IF
    as you can see this also writes the numbers to memory backwards
    and is way too slow. but it does work.

    if you need to see more of the code just let me know.


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




    [This message has been edited by Buck Huffman (edited May 02, 2002).]
Working...
X