Shop OBEX P1 Docs P2 Docs Learn Events
DAT longs tinto bytes, Would someone smack me? — Parallax Forums

DAT longs tinto bytes, Would someone smack me?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2014-07-30 08:34 in Propeller 1
I've starring at some DAT longs that I need to convert to DAT bytes.

The conversion is on the tip of my fingers, but I can't remember what it should look like.

Could someone write a DAT "BYTES" example of the sample below?
DAT

tiles
        '' name=FONT_0, palette=0
        long    $000FFF00
        long    $00F00FF0
        long    $0FF000FF
        long    $0FF000FF
        long    $0FF000FF
        long    $00FF00F0
        long    $000FFF00
        long    $00000000

Utimately I'm working on the determination of how this looks as bytes in @tiles, but one step at a time. :)

Thanks
Jeff

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-29 13:50
    Is this what you mean?
    DAT
    
    tiles
            '' name=FONT_0, palette=0
            byte    $00, $0F, $FF, $00
            byte    $00, $F0, $0F, $F0
            byte    $0F, $F0, $00, $FF
            byte    $0F, $F0, $00, $FF
            byte    $0F, $F0, $00, $FF
            byte    $00, $FF, $00, $F0
            byte    $00, $0F, $FF, $00
            byte    $00, $00, $00, $00
    
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-07-29 13:53
    Yes, that's the way i thought it should look, but for reason my conversion isn't working on this end...

    Perhaps it's my conversion routines.. back to the drawing board... :)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-07-29 13:57
    I second Dunae's example, except for one thing: his bytes are reversed. Remember that the Prop is a little-endian beast, so the least-significant byte in a long comes first.

    -Phil
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-07-29 14:19
    @Phil,

    That explains why my characters are suddenly looking reversed :)

    Ok, here's what I'm doing..

    I've got a file I'm opening using FSRW which contains LONG style entries. (000FFF00 might be on a line)

    I'm reading the first byte into "b", then the second byte into "c"

    Then I'm passing them into this lovely routine.. (I'm sure there is a MUCH MORE elegant way to do this, but my brain thinks like this chunk of code.)
    pub convert_sd_data(b,c)
    
      if b == 48
         case c
            48: return $00
            49: return $01
            50: return $02
            51: return $03
            52: return $04
            53: return $05
            54: return $06
            55: return $07
            56: return $08
            57: return $09
            65: return $0A
            66: return $0B
            67: return $0C
            68: return $0D
            69: return $0E
            70: return $0F
      if b == 49
         case c
            48: return $10
            49: return $11
            50: return $12
            51: return $13
            52: return $14
            53: return $15
            54: return $16
            55: return $17
            56: return $18
            57: return $19
            65: return $1A
            66: return $1B
            67: return $1C
            68: return $1D
            69: return $1E
            70: return $1F
      if b == 50
         case c
            48: return $20
            49: return $21
            50: return $22
            51: return $23
            52: return $24
            53: return $25
            54: return $26
            55: return $27
            56: return $28
            57: return $29
            65: return $2A
            66: return $2B
            67: return $2C
            68: return $2D
            69: return $2E
            70: return $2F
      if b == 51
         case c
            48: return $30
            49: return $31
            50: return $32
            51: return $33
            52: return $34
            53: return $35
            54: return $36
            55: return $37
            56: return $38
            57: return $39
            65: return $3A
            66: return $3B
            67: return $3C
            68: return $3D
            69: return $3E
            70: return $3F
      if b == 52
         case c
            48: return $40
            49: return $41
            50: return $42
            51: return $43
            52: return $44
            53: return $45
            54: return $46
            55: return $47
            56: return $48
            57: return $49
            65: return $4A
            66: return $4B
            67: return $4C
            68: return $4D
            69: return $4E
            70: return $4F
      if b == 53
         case c
            48: return $50
            49: return $51
            50: return $52
            51: return $53
            52: return $54
            53: return $55
            54: return $56
            55: return $57
            56: return $58
            57: return $59
            65: return $5A
            66: return $5B
            67: return $5C
            68: return $5D
            69: return $5E
            70: return $5F
      if b == 54
         case c
            48: return $60
            49: return $61
            50: return $62
            51: return $63
            52: return $64
            53: return $65
            54: return $66
            55: return $67
            56: return $68
            57: return $69
            65: return $6A
            66: return $6B
            67: return $6C
            68: return $6D
            69: return $6E
            70: return $6F
      if b == 55
         case c
            48: return $70
            49: return $71
            50: return $72
            51: return $73
            52: return $74
            53: return $75
            54: return $76
            55: return $77
            56: return $78
            57: return $79
            65: return $7A
            66: return $7B
            67: return $7C
            68: return $7D
            69: return $7E
            70: return $7F
      if b == 56
         case c
            48: return $80
            49: return $81
            50: return $82
            51: return $83
            52: return $84
            53: return $85
            54: return $86
            55: return $87
            56: return $88
            57: return $89
            65: return $8A
            66: return $8B
            67: return $8C
            68: return $8D
            69: return $8E
            70: return $8F
      if b == 57
         case c
            48: return $90
            49: return $91
            50: return $92
            51: return $93
            52: return $94
            53: return $95
            54: return $96
            55: return $97
            56: return $98
            57: return $99
            65: return $9A
            66: return $9B
            67: return $9C
            68: return $9D
            69: return $9E
            70: return $9F
      if b == 65
         case c
            48: return $A0
            49: return $A1
            50: return $A2
            51: return $A3
            52: return $A4
            53: return $A5
            54: return $A6
            55: return $A7
            56: return $A8
            57: return $A9
            65: return $AA
            66: return $AB
            67: return $AC
            68: return $AD
            69: return $AE
            70: return $AF
      if b == 66
         case c
            48: return $B0
            49: return $B1
            50: return $B2
            51: return $B3
            52: return $B4
            53: return $B5
            54: return $B6
            55: return $B7
            56: return $B8
            57: return $B9
            65: return $BA
            66: return $BB
            67: return $BC
            68: return $BD
            69: return $BE
            70: return $BF
      if b == 67
         case c
            48: return $C0
            49: return $C1
            50: return $C2
            51: return $C3
            52: return $C4
            53: return $C5
            54: return $C6
            55: return $C7
            56: return $C8
            57: return $C9
            65: return $CA
            66: return $CB
            67: return $CC
            68: return $CD
            69: return $CE
            70: return $CF
      if b == 68
         case c
            48: return $D0
            49: return $D1
            50: return $D2
            51: return $D3
            52: return $D4
            53: return $D5
            54: return $D6
            55: return $D7
            56: return $D8
            57: return $D9
            65: return $DA
            66: return $DB
            67: return $DC
            68: return $DD
            69: return $DE
            70: return $DF
      if b == 69
         case c
            48: return $E0
            49: return $E1
            50: return $E2
            51: return $E3
            52: return $E4
            53: return $E5
            54: return $E6
            55: return $E7
            56: return $E8
            57: return $E9
            65: return $EA
            66: return $EB
            67: return $EC
            68: return $ED
            69: return $EE
            70: return $EF
      if b == 70
         case c
            48: return $F0
            49: return $F1
            50: return $F2
            51: return $F3
            52: return $F4
            53: return $F5
            54: return $F6
            55: return $F7
            56: return $F8
            57: return $F9
            65: return $FA
            66: return $FB
            67: return $FC
            68: return $FD
            69: return $FE
            70: return $FF
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-29 14:48
    It looks like you're trying to convert ASCII hexadecimal character to a number?

    PST has a neat little "StrToBase" object which does this nicely.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-07-29 15:22
    Thanks Duane!

    I've got mine ultra complex routine working now thanks to you and Phil, but I'll also grab that StrToBase and see if we can do this conversion a little more intelligently than throw rocks at it. :)

    Jeff
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-07-29 22:19
    Dropping in StrToBase just felt a little too much like cheating after writing such an elaborate routine...

    Here's my much shorter version.. I'll probably replace it with some decent math after I've had some sleep. :)
    pub convert_sd_data(b,c) | calc
    
         case b
            48: calc :=$00
            49: calc :=$10
            50: calc :=$20
            51: calc :=$30
            52: calc :=$40
            53: calc :=$50
            54: calc :=$60
            55: calc :=$70
            56: calc :=$80
            57: calc :=$90
            65: calc :=$A0
            66: calc :=$B0
            67: calc :=$C0
            68: calc :=$D0
            69: calc :=$E0
            70: calc :=$F0
    
         case c
            48: return $00+calc
            49: return $01+calc
            50: return $02+calc
            51: return $03+calc
            52: return $04+calc
            53: return $05+calc
            54: return $06+calc
            55: return $07+calc
            56: return $08+calc
            57: return $09+calc
            65: return $0A+calc
            66: return $0B+calc
            67: return $0C+calc
            68: return $0D+calc
            69: return $0E+calc
            70: return $0F+calc
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-30 07:29
    I'll probably replace it with some decent math after I've had some sleep. :)

    Just a hint. You can use:
    case b
        48..57: calc := b - 48
    

    The same thing written differently:
    case b
        "0".."9": calc := b - "0"
    

    Do the same sort of thing with "A".."F".
    Using this sort of arrangement you could shorten your case lists down to two groups each.

    I know there are many versions of this sort of conversion floating around on the forum.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2014-07-30 08:34
    Dang it Duane!

    I was just going to start playing with that challenge after some coffee this morning. I've only downed half a cup and your message makes perfect sense. :) Your hint was TOO good. :):)

    Thanks again!
Sign In or Register to comment.