leotranslat.c
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* F i l e N a m e : l e o t r a n s l a t .c
*
****************************************************************************
* (C) Copyright ALPS Electric Co., Ltd. 1995-1996
****************************************************************************
* Version:
*
* ver date
* ---- ---------
* 1.02 '96-04-05 Change LEOVZONE_PZONEHD_TBL[] .
* 1.01 '96-02-27 Rename file name translat.c to leotranslat.c
* 1.00 '95-12-20 Initial Revision.
****************************************************************************
*/
#include <ultra64.h>
#include "leodefine.h"
#include "leodrive.h"
#include "leoappli.h"
/*************************************/
/* PROTOTYPE */
/*************************************/
void leoTranslate(void);
/*************************************/
/* EXTERNAL DEFINED FUNCTIONS */
/*************************************/
extern u16 leoLba_to_vzone(u32 lba);
/*************************************/
/* EXTERNAL DEFINED RAMS */
/*************************************/
extern u16 LEOVZONE_TBL[DISK_TYPES][VZONES_PER_DRV];
extern u16 LEOBYTE_TBL2[ZONES_PER_DRV];
extern u8 LEOVZONE_PZONEHD_TBL[DISK_TYPES][VZONES_PER_DRV];
extern OSMesg LEOcur_command;
extern union leo_sys_form LEO_sys_data;
extern u8 LEOdisk_type;
/*************************************/
/* MACRO */
/*************************************/
#define trans_cmd ((LEOCmdTranslate *)LEOcur_command)
/* ==========================================================================
* Function : leoTranslate
* --------------------------------------------------------------------------
* Description : Execute translate command
* --------------------------------------------------------------------------
* IN : LEOcur_command
* OUT : *LEOcur_command
* ARG : non
* RET : non
* ==========================================================================
*/
void leoTranslate(void)
{
u32 lba;
u32 calc_bytes;
u32 calc_blks;
u32 byte_p_blk;
u16 zone,vzone;
u8 flag;
if (trans_cmd->start_lba > MAX_L_LBA)
{
/* LBA out of range */
trans_cmd->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
trans_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
lba = trans_cmd->start_lba + SYSTEM_LBAS;
calc_bytes = calc_blks = 0;
flag = vzone = 1;
if (trans_cmd->header.control & LEO_CONTROL_TBL)
{
/* translate byte to block */
calc_bytes = trans_cmd->in_param;
while (calc_bytes)
{
if (flag || (lba == LEOVZONE_TBL[LEOdisk_type][vzone]))
{
vzone = leoLba_to_vzone(lba);
zone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
if (zone > (u8)7)
zone -= (u8)7;
byte_p_blk = LEOBYTE_TBL2[zone];
}
if (calc_bytes < byte_p_blk)
calc_bytes = 0;
else
calc_bytes -= byte_p_blk;
calc_blks++;
lba++;
if ((calc_bytes) && (lba > (u32)MAX_P_LBA))
{
trans_cmd->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
trans_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
flag = 0;
}
trans_cmd->out_param = calc_blks;
}
else
{
/* translate block to byte */
calc_blks = trans_cmd->in_param;
while (calc_blks)
{
if (flag || (lba == LEOVZONE_TBL[LEOdisk_type][vzone]))
{
vzone = leoLba_to_vzone(lba);
zone = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
if (zone > (u8)7)
zone -= (u8)7;
byte_p_blk = LEOBYTE_TBL2[zone];
}
calc_bytes += byte_p_blk;
calc_blks--;
lba++;
if ((calc_blks) && (lba > (u32)MAX_P_LBA))
{
trans_cmd->header.sense = LEO_SENSE_LBA_OUT_OF_RANGE;
trans_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
flag = 0;
}
trans_cmd->out_param = calc_bytes;
}
#ifdef _ERRCHK
if (trans_cmd->header.sense = trans_cmd->header.reserve1 )
trans_cmd->header.status = LEO_STATUS_CHECK_CONDITION;
else
trans_cmd->header.status = LEO_STATUS_GOOD;
#else
trans_cmd->header.status = LEO_STATUS_GOOD;
#endif
}